Tuesday, May 7, 2013

How to statically assign an IP address in Linux...and keep it after reboot

Whether you're using Fedora version gazillion, Ubuntu 10, or Backtrack, I'm sure you've experienced some issue with setting your network configuration...and ensuring the figures you enter actually stick after a reboot. How annoying is that? It certainly makes you feel like a noob when you can't get your systems to talk because of an IP configuration error.

Well, you're not alone. There are some variances of Linux that do not save the IP configuration you input unless you hard code it into the appropriate networking file. You can set it 'ifconfig eth0 192.168.x.x/24 or go into the GUI of Fedora, but it loses its config after a simple reboot. Here's a simple way to avoid all that mess:



IP Configuration File location:

  • Debian / Ubuntu Linux - /etc/network/interfaces
    • # sudo vi /etc/network/interfaces
    • iface eth0 inet static
           address 192.168.1.222
           network 192.168.1.0
           netmask 255.255.255.0
           broadcast 192.168.1.255
           gateway 192.168.1.1
      <Once done, enter Esc, :wq> This saves your configuration> 
      • Configure your DNS server:
        • # vi /etc/resolv.conf
        • search mydomain.com
          nameserver 192.168.1.10
          nameserver 8.8.8.8
          nameserver 202.54.2.5
      # /etc/init.d/networking restart <This will restart your network connection> 
  • RHEL / Red hat / Fedora / CentOS Linux eth0 config file - /etc/sysconfig/network-scripts/ifcfg-eth0
  • RHEL / Red hat / Fedora / CentOS Linux eth1 config file - /etc/sysconfig/network-scripts/ifcfg-eth1
# cat /etc/sysconfig/network-scripts/ifcfg-eth0 
# Intel Corporation 82573E Gigabit Ethernet Controller (Copper)
DEVICE=eth0
BOOTPROTO=static
DHCPCLASS=
HWADDR=00:54:18:56:A9:2D
IPADDR=192.168.1.57
NETMASK=255.255.255.0
ONBOOT=yes


Hopefully this helps some.

No comments:

Post a Comment