Changing IP to static on Fedora,CentOS and Oracle Linux

DHCP is great but there usually comes a time when you need to make sure that your IP stays always the same. This post outlines the steps you can take to setup a static IP on Fedora, Centos and Oracle Linux.

Before you begin do these two steps in terminal:

yum -y install net-tools

ip a

After ip a, you will see something like this:

2: eno1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether dc:4a:3e:43:dc:1c brd ff:ff:ff:ff:ff:ff
inet 9.1.1.11/24 brd 9.1.1.255 scope global dynamic eno1
valid_lft 68056sec preferred_lft 68056sec
inet6 fe80::593e:cf18:df4e:f815/64 scope link
valid_lft forever preferred_lft forever

Take note of your network adapter name(eno1).

Get your current IP (inet line)
9.1.1.11

Broadcast address(brd)
9.1.1.255

Get your gateway details by typing route -n

It will show something like:
9.1.1.1

Change network adapter settings to static.

nano /etc/sysconfig/network-scripts/ifcfg-eno1:

DEVICE=eno1
BOOTPROTO=”static”

ONBOOT=”yes”
IPADDR=9.1.1.11
NETMASK=255.255.255.0
BROADCAST=9.1.1.255
NETWORK=9.1.1.0
GATEWAY=9.1.1.1

Now check your /etc/resolv.conf and verify that it has correct search lines and nameservers. Usually it should be something like this:

search lan.local
nameserver 9.1.1.1 -> Notice that this here is the same as  our gateway.
nameserver 8.8.8.8 -> Google DNS1
nameserver 8.8.4.4 -> Google DNS2

Last steps are all about stopping NetworkManager and restarting the network:

systemctl stop NetworkManager
chkconfig NetworkManager off
service network restart

Your are done. Now your network configuration should have a static IP.
Test connectivity with ping: ping google.fi