During the
installation of Ubuntu on your server an IP address was most likely obtained
automatically. This dynamic IP address assignment will need to be changed to a
static IP address. This section will cover the simple network configuration
changes needed to set a static IP network address for your server. For this
section, the directions assume the configuration is for a node with only one
interface (eth0) after a default installation.
Note
These
instructions assume that the reader is familiar with opening, editing and
saving files at the command line. Please consult your OS documentation if you
need assistance with these tasks.
Most Linux systems have a
few commands that can be used to find out what the current network
configuration is, for example:
ifconfig -a
You can also
use variations of the ip command:
ip addr
Basic network
configuration and hostname on a Ubuntu system are stored in several files which
must be edited to create a working configuration:
· /etc/network/interfaces describes the network interfaces
· /etc/hostname configures the nameserver credentials
· /etc/hosts resolves IP addresses to hostnames
Once the new
configuration is saved the interface must be restarted.
Changing
Network Configuration
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:
# 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
Open
your /etc/network/interfaces file, locate the:
· "iface
eth0..." line and change dynamic to static
· address line
and change the address to the static IP address
· netmask line
and change the address to the correct subnet mask
· gateway line
and change the address to the correct gateway address
· dns-nameservers
line and change (or add) the nameserver information
If you aren't
certain which IP address, subnet mask, gateway or dns-nameservers you need,
please consult with your network administrator for the correct information.
When you are
happy with your configuration restart the interface with the command below. If
you are connected using SSH you will lose your connection, re-connect using the
new IP address:
ifdown eth0; ifup eth0
Changing the
Hostname
To change the
hostname to your preferred node name (example: prodnode01), you have to edit
the /etc/hostname file:
prodnode01
Adding the
FQDN (Hostname)
To ensure
your server traffic will be routing correctly add the server's Fully Qualified
Domain Name (FQDN) and IP address to the hosts file. Open the /etc/hosts file and add a line with the static IP
address and the FQDN, similar to the example shown below:
192.168.0.0
prodnode01.acme.com
With all your
files edited and saved, you should reboot so the new name and configuration
will be used.
Reboot the
system and then use ifconfig or ipaddr to confirm that your new configuration
is available. You can also use hostname -f to verify the hostname change,