Here’s a little primer on static Internet Protocol (IP) Addresses. Computers usually have the ability to grab a Dynamic Host Configuration Protocol (DHCP) address by default. Most networks are set to give out these dynamic IP addresses to any device that gets on the network and says, “I’m here! Give me an IP address so that I can use Google!”
The trouble with DHCP addresses is that they are dynamic. When a DHCP “lease” runs out, the computer or device may grab another available DHCP IP address. Normally this is ok and allows seamless Internet access to any computer; however, sometimes the need arises to statically assign an IP address for remote access, file transfers, or any other number of reasons.
To get a static IP address for your computer, submit a help ticket at http://cns.utexas.edu/help. Once you receive an IP assignment, follow the instructions below to get the IP Address and additional needed information onto your computer’s network connection.
NOTE: To make these changes, you must have an account with administrative rights on the machine. You will either need to login as root, or be able to use the "sudo" command on your machine. In the following, we assume you are logged in as root.
NOTE: Since the graphical interfaces change so much between Linux distributions, we're only going to show command line configuration here. While the command line interface does change between Linux distributions, it changes less than the graphical interfaces.
NOTE: We provide directions below for the most popular Linux distributions in CNS. If you use another distribution (like Gentoo, OpenSUSE, etc), you can contact the CNS Help Desk at http://cns.utexas.edu/help/ for additional instructions or help. There is also a tremendous amount of helpful information on the Internet on this topic. If the steps here do not work for you, Google for it. You'll almost certainly be able to find the procedure for the particular distribution of Linux you are running.
NOTE: Since part of the process described below is restarting the networking, you should always execute these commands from a local login to the machine, and not a remote sessions such as via ssh, vnc, etc.
How to add a static IP Address to a Linux computer
1) Setting your system's hostname
You should first set your system's hostname to the Fully Qualified Domain Name assigned to it. Assuming the assigned hostname for your machine is "pluto.cns.utexas.edu", you would use the following commands to set the hostname:
Red Hat/CentOS/SL 7+, Ubuntu 14.04+,
hostnamectl set-hostname "pluto.cns.utexas.edu"
|Older Ubuntu, Debian, Arch||
echo "pluto.cns.utexas.edu" > /etc/hostname
|Older Red Hat/CentOS/SL, Fedora||
echo "HOSTNAME=pluto.cns.utexas.edu" >> /etc/sysconfig/network
2) Edit your /etc/hosts file
Next, you should edit your /etc/hosts file to add a line containing your assigned IP address and FQDN. Assuming again your hostname is "pluto.cns.utexas.edu" and your IP address is 22.214.171.124, you can do this using the following command (all versions):
echo "126.96.36.199 pluto.cns.utexas.edu" >> /etc/hosts
3) Setting the actual IP address
The first step is to figure out the name of your connected network interface. Run the command:
from the command prompt. It will output something like:
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: p4p1: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN mode DEFAULT group default qlen 1000
link/ether 00:0a:f7:69:7d:5d brd ff:ff:ff:ff:ff:ff
3: em1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
link/ether 98:90:96:bd:1c:fc brd ff:ff:ff:ff:ff:ff
Now you need to set the IP address and additional information needed. The file and contents vary somewhat by Linux distribution. We assume the connected network interface name is em1 here – use whatever you determined to be your network name in the step above if it is different.
Debian and Ubuntu:
Edit the file /etc/network/interfaces and make the changes needed to specify your assigned IP address, Gateway, and Subnet Mask. The file should have comments in it to help you identify what needs to be done. Assuming again we are assigned 188.8.131.52 and pluto.cns.utexas.edu, and the network is a /24 network, then the file would read:
# lo is the loopback interface, em1 is the active ethernet interface auto lo em1 iface lo inet loopback # Configuration for em1 # This line ensures that the interface will be brought up during boot auto em1 allow-hotplug em1 # The address, gateway and netmask are necessary. iface em1 inet static address 184.108.40.206 gateway 220.127.116.11 netmask 255.255.255.0 dns-search utexas.edu dns-namesevers 18.104.22.168, 22.214.171.124
You would then restart the network interface using the commands:
ifdown -a; ifup -a
Red Hat 7, CentOS 7, Scientific Linux 7, Fedora 22+:
These instructions are only for the newest versions of these operating system. See below for older versions.
On Red Hat based systems, each interface has its own configuration file /etc/sysconfig/networking-scripts/ifcfg-INTERFACE , where INTERFACE is the name of the interface. To configure em1, for example, you would edit the file /etc/sysconfig/networking-scripts/ifcfg-em1, and set it to something like the following:
DEVICE=em1 BOOTPROTO=static HWADDR=98:90:96:bd:1c:fc IPADDR=126.96.36.199 NETMASK=255.255.255.0 GATEWAY=188.8.131.52 DEFROUTE=yes NM_CONTROLLED=no ONBOOT=yes IPV6INIT=no DOMAIN="ph.utexas.edu" DNS1=184.108.40.206 DNS2=220.127.116.11
Then you would restart the network interface using the commands:
nmcli con reload
service network restart
On Arch Linux, the configuration file for network interface is /etc/netctl/INTERFACE , where INTERFACE is the name of the interface. To configure em1, for example, edit /etc/netctl/em1, and make it look like this:
Description="A basic static ethernet connection" Interface=em1 Connection=ethernet IP=static Address=('18.104.22.168/24') Gateway=('22.214.171.124') DNS=('126.96.36.199', '188.8.131.52')
Then start the network interface and enable the interface to start automatically at boot with the commands:
netctl restart em1
netctl enable em1
Red Hat, CentOS, Scientific Linux, Fedora
If you are not running one of the newer versions shown above, then you would edit the file /etc/sysconfig/networking-scripts/ifcfg-INTERFACE as follows:
# Configuration for em1 DEVICE=em1 BOOTPROTO=none HWADDR=98:90:96:bd:1c:fc ONBOOT=yes DEFROUTE=yes NM_CONTROLLED=no IPADDR=184.108.40.206 NETMASK=255.255.0.0 GATEWAY=220.127.116.11 IPV6INIT=no DOMAIN="ph.utexas.edu" DNS1=18.104.22.168 DNS2=22.214.171.124
Then restart the network interface using the command:
service network restart
4) Configure your DNS servers if necessary
host -a google.com
nameserver 126.96.36.199 nameserver 188.8.131.52
Written by CNS OIT staff
Questions or comments? The best and easiest way to contact us is via the CNS Help Desk form.