Lampros - Weird Bricks

Setting up a Static IP Address on CentOS 7

24 August, 2014 | CentOS

Continuing from installing CentOS 7 on my old desktop I wanted to set up a static IP address so I can essentially have a headless server that I can always reach at the same IP address.

In this case I want it to have the IP 192.168.2.100.

Interestingly, although I have a network interface enp0s7:

ifconfig enp0s7

Output:

enp0s7: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.2.10  netmask 255.255.255.0  broadcast 192.168.2.255
        inet6 fe80::21e:90ff:fe77:865c  prefixlen 64  scopeid 0x20<link>
        ether 00:1e:90:77:86:5c  txqueuelen 1000  (Ethernet)
        RX packets 534  bytes 45293 (44.2 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 443  bytes 61545 (60.1 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

I don't have a corresponding /etc/sysconfig/network-scripts/ifcfg-enp0s7 file to edit:

ls /etc/sysconfig/network-scripts/ifcfg-*

Output:

/etc/sysconfig/network-scripts/ifcfg-lo

So I'm going to go ahead and create one manually:

vim /etc/sysconfig/network-scripts/ifcfg-enp0s7

And add the following contents:

DEVICE="enp0s7"
ONBOOT="yes"
NM_CONTROLLED="no"
TYPE=Ethernet
BOOTPROTO=static
IPADDR=192.168.2.100
NETMASK=255.255.255.0
GATEWAY=192.168.2.1

Then to make the changes take, I'll issue a:

service network restart

Since I was smart enough to do this over SSH (oops) my SSH session disconnected - luckily everything worked and now I can SSH to the new address:

ssh root@192.168.2.100
Warning: Permanently added '192.168.2.100' (ECDSA) to the list of known hosts.
root@192.168.2.100's password:
Last login: Sun Aug 24 12:22:13 2014 from 192.168.2.3

Check ifconfig again:

ifconfig enp0s7
enp0s7: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.2.100  netmask 255.255.255.0  broadcast 192.168.2.255
        inet6 fe80::21e:90ff:fe77:865c  prefixlen 64  scopeid 0x20<link>
        ether 00:1e:90:77:86:5c  txqueuelen 1000  (Ethernet)
        RX packets 937  bytes 81673 (79.7 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 723  bytes 96449 (94.1 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

Reboot the system to be 100% certain that this is permanent:

reboot

SSHing in to the system at 192.168.2.100 worked without issue and ifconfig confirms this:

ifconfig enp0s7
enp0s7: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.2.100  netmask 255.255.255.0  broadcast 192.168.2.255
        inet6 fe80::21e:90ff:fe77:865c  prefixlen 64  scopeid 0x20<link>
        ether 00:1e:90:77:86:5c  txqueuelen 1000  (Ethernet)
        RX packets 56  bytes 7349 (7.1 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 70  bytes 10412 (10.1 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

SOURCES: https://www.centos.org/forums/viewtopic.php?f=16&t=45173