
Quick Guide: Set Static IP Address Ubuntu
If you’ve chosen the shortcuts through your Ubuntu installation, chances are you did not spend a lot of time setting up the network. I prefer using static IP addresses for my development machines for many reasons, but primarily because it helps with organizing and accessing them. Below is a quick guide on how to set one up.
1. Edit the network configuration
sudo nano /etc/network/interfaces
Change it to the following:
# The primary network interface
auto eth0
iface eth0 inet static
address 192.168.0.100
netmask 255.255.255.0
network 192.168.0.0
broadcast 192.168.0.255
gateway 192.168.0.1
Then restart your network configuration:
sudo /etc/init.d/networking restart
2. Edit your hosts file
sudo nano /etc/hosts
Change it to the following:
127.0.0.1 localhost.localdomain localhost
192.168.0.100 serv1.example.com serv1
3. Set the hostname
sudo echo serv1.example.com > /etc/hostname
4. Apply the hostname
sudo /etc/init.d/hostname.sh start
5. Check the hostname
hostname
6. Check the full hostname (FQDN)
hostname -f
If everything was done correctly, both commands should display the same name.
NOTE: This should work on Ubuntu versions 8.04 (LTS) or earlier.