Skip to main content

SETTING STATIC IP FOR UBUNTU


Important Networking configuration files:
/etc/network/interfaces describes the network interfaces
/etc/hostname configures the nameserver credentials
/etc/hosts resolves IP addresses to hostnames

To manualy set IP address:
Below is an example of a static IP configuration on a system with only one Ethernet interface (eth0) and 10.0.0.41/24 for the IP address. Opening the /etc/network/interfaces file will produce:
#vi /etc/network/interfaces

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
iface eth0 inet static
    address 10.0.0.41
    netmask 255.255.255.0
    network 10.0.0.0
    broadcast 10.0.0.255
    gateway 10.0.0.1
    dns-nameservers 10.0.0.1 8.8.8.8
    dns-domain acme.com
    dns-search acme.com

Now make interface down
#ifdown eth0
Now turn it up
#ifup eth0
Now restart network
#service networking restart

Setting FQDN:
Open the /etc/hosts file and add a line with the static IP address and the FQDN, similar to the example shown below:
#vi /etc/hosts
192.168.0.0 mylinux.com

Setting Hostname:
To change the hostname to your preferred node name (example: prodnode01), you have to edit the /etc/hostname file:
#vi /etc/hostname
mylinux