DarkMatter in Cyberspace
  • Home
  • Categories
  • Tags
  • Archives

Set Static IP on Linux


Ubuntu

You need to know the static IP, netmask and gateway IP. To test your network, set static IP temporarily:

# ip addr   // get the interface name: eth0
# ifconfig eth0 10.32.22.10 netmask 255.255.255.0
# route add default gw 10.32.22.254 eth0

Then test network with "ping" command. If it's OK, set it permanently:

# cat /etc/network/interfaces  // before modification: dhcp
auto eth0
iface eth0 inet dhcp
# cat /etc/network/interfaces  // after modification: static IP
auto eth0
iface eth0 inet static
address 10.32.22.10
netmask 255.255.255.0
gateway 10.32.22.254

Now reboot the static IP will take effect.

Note that the value of "gateway" is determined by route -n, the value in column "Gateway" after destination "0.0.0.0".

Arch Linux

# ip addr flush enp2s0
# ip addr add 10.32.22.10/24 dev enp2s0
# ip route add default via 10.32.22.254


Published

May 4, 2014

Last Updated

May 4, 2014

Category

Tech

Tags

  • ip 3
  • Linux 158
  • static 2
  • ubuntu 61

Contact

  • Powered by Pelican. Theme: Elegant by Talha Mansoor