If you have a new installation of Ubuntu Server, you may want to configure a static IP address on it instead of relying on DHCP for a server. It’s not as simple as some platforms, but here’s the quick and dirty instructions on setting static IPs in Ubuntu Server:
1. Login with the admin user you created during the install.
2. Check out the contents of the /etc/network/interfaces file:
penguin@wwwsvr07:~$ more /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 # This is an autoconfigured IPv6 interface auto eth0 iface eth0 inet6 auto penguin@wwwsvr07:~$
As you can see, it’s setup for IPv6 auto config by default in my case.
3. Before you change it, lets create a backup of the interfaces file in case it gets messed up while editing (never hurts to have a back out plan):
penguin@wwwsvr07:~$ sudo cp /etc/network/interfaces /etc/network/interfaces.backup [sudo] password for penguin:
4. Now that you have a backup, lets edit the original, specifically the stuff after “iface eth0”
penguin@wwwsvr07:~$ sudo 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 # This is an autoconfigured IPv6 interface auto eth0 iface eth0 inet static address 10.11.100.80 netmask 255.255.255.0 gateway 10.11.100.1 dns-nameservers 10.76.76.101 10.76.76.102 ### BEGIN IPV6 Config iface eth0 inet6 static pre-up modprobe ipv6 address 2001:DB8:0:100::80 netmask 64 gateway 2001:DB8:0:100::1 dns-nameservers 2001:DB8:0:76::101 2001:DB8:0:76::102 ### END IPV6 Config
Exit vi with :wq to write the changes to the file and quit.
5. All that’s left is to restart the network interface to have the changes take effect:
penguin@wwwsvr07:~$ sudo ifdown eth0 penguin@wwwsvr07:~$ sudo ifup eth0 Waiting for DAD... Done! penguin@wwwsvr07:~$
This should be all you need to configure a static IP address on your Ubuntu server. Now you can start configuring services and securing your box!