Setting a Static IP

Issues related to configuring your network
mark9090
Posts: 13
Joined: 2019/03/22 11:10:36

Setting a Static IP

Post by mark9090 » 2019/03/22 11:22:22

Hello,

My CentOS 7.4 server currently acquires its IP address over DHCP from my router. The problem I have with this is the server is choosing to utilise a public dynamic IP which keeps changing.

I would like the server to acquire a permanent static IP using 'bootproto=static' which can be set in my network configuration file at: /etc/sysconfig/network-scripts/ifcfg-enp2s0 however I am having hard time providing the correct details for a static setup.

A guide I have found on setting up bootproto=static can be found here: https://www.techrepublic.com/article/ho ... -centos-7/ .

I'm unsure on what information to provide for the following entries:-
IPADDR=
NETMASK=
GATEWAY=
DNS1=
My server uses the IP 81.143.9.98 for all virtual accounts so would I pass IPADDR=81.143.9.98 as the entry? My ISP tells me my netmask=255.255.255.248 which appears accurate. My router is presumably the gateway which has the IP 192.168.1.254 AND 81.143.9.97 so which IP address would I use for the GATEWAY= entry? Lastly, is the DNS1= entry the same has the GATEWAY= entry?


Many thanks in advance for any advice.

User avatar
TrevorH
Site Admin
Posts: 33202
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: Setting a Static IP

Post by TrevorH » 2019/03/22 15:53:03

First off, CentOS 7.4 is way out of date and needs updating. 7.4 came out in Aug 2017 so is now more than 18 months old. You need to yum update to 7.6 ASAP.

When you use DHCP, do you get an ip address given to you that is similar to 81.143.9.98? Or do you get one like 192.168.1.x?
The future appears to be RHEL or Debian. I think I'm going Debian.
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 and 6 are deadest, do not use them.
Use the FAQ Luke

mark9090
Posts: 13
Joined: 2019/03/22 11:10:36

Re: Setting a Static IP

Post by mark9090 » 2019/03/22 16:32:43

TrevorH wrote:
2019/03/22 15:53:03
First off, CentOS 7.4 is way out of date and needs updating. 7.4 came out in Aug 2017 so is now more than 18 months old. You need to yum update to 7.6 ASAP.

When you use DHCP, do you get an ip address given to you that is similar to 81.143.9.98? Or do you get one like 192.168.1.x?
I will update CentOS to 7.6 ASAP. Thanks.

How would I check which IP address is currently assigned through DHCP?

User avatar
jlehtone
Posts: 4523
Joined: 2007/12/11 08:17:33
Location: Finland

Re: Setting a Static IP

Post by jlehtone » 2019/03/22 16:37:16

mark9090 wrote:
2019/03/22 11:22:22
server currently acquires its IP address over DHCP from my router. The problem I have with this is the server is choosing to utilise a public dynamic IP which keeps changing.
Configure your DHCP server in your router to hand out persistent IP address for your server's MAC. Most cheap crap routers support that option. All pro routers do too.


Your question, however, implies that you don't want to keep your server in the subnet managed by your router.
You want to move your server to the subnet managed by your ISP's DHCP server?
That would put your server outside of your "home LAN".

Is that really what you want?


Information commands:

Code: Select all

ip ad
ip ro
nmcli
nmcli c s

mark9090
Posts: 13
Joined: 2019/03/22 11:10:36

Re: Setting a Static IP

Post by mark9090 » 2019/03/22 16:48:14

I would just like to achieve the static set-up detailed here: https://www.techrepublic.com/article/ho ... -centos-7/ as the router is assigning dynamic (ever-changing) IP addresses to the server over DHCP; I would like the server to use one persistent IP address instead. The router does not support assigning IP's based on the server's MAC address.

lightman47
Posts: 1521
Joined: 2014/05/21 20:16:00
Location: Central New York, USA

Re: Setting a Static IP

Post by lightman47 » 2019/03/22 18:33:50

The router does not support assigning IP's based on the server's MAC address.
How old is this thing?

You may certainly do static addresses if you wish; folk are just trying to save you the headaches that follow. DHCP can be set up so that every machine gets an assigned address of your choosing.

;)

mark9090
Posts: 13
Joined: 2019/03/22 11:10:36

Re: Setting a Static IP

Post by mark9090 » 2019/03/22 18:54:30

I used the ip ro command and this was the output:-
ip route
default via 192.168.1.254 dev enp2s0
81.143.9.0/24 dev enp2s0 proto kernel scope link src 81.143.9.98
81.143.9.98 dev enp2s0 scope link src 81.143.9.98
81.143.9.99 dev enp2s0 scope link src 81.143.9.99
81.143.9.100 dev enp2s0 scope link src 81.143.9.100
81.143.9.101 dev enp2s0 scope link src 81.143.9.101
192.168.1.0/24 dev enp2s0 proto kernel scope link src 192.168.1.67

mark9090
Posts: 13
Joined: 2019/03/22 11:10:36

Re: Setting a Static IP

Post by mark9090 » 2019/03/22 18:59:12

lightman47 wrote:
2019/03/22 18:33:50
The router does not support assigning IP's based on the server's MAC address.
How old is this thing?

You may certainly do static addresses if you wish; folk are just trying to save you the headaches that follow. DHCP can be set up so that every machine gets an assigned address of your choosing.

;)
If DHCP can allow a machine to be assigned a static permanent IP address I would like to go down that route. At this moment my /etc/sysconfig/network-scripts/ interface file has the bootproto=DHCP enabled which is causing the server to utilise a random public dynamic IP address. I need the server to acquire the non-changing public IP of 81.143.9.98 as its main IP address.
Last edited by mark9090 on 2019/03/22 19:06:34, edited 1 time in total.

User avatar
TrevorH
Site Admin
Posts: 33202
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: Setting a Static IP

Post by TrevorH » 2019/03/22 19:00:53

That is an extremely odd set up and the reason why I was asking about the current ip addresses given to you by DHCP.

What is the output from ip addr show and ip link show
The future appears to be RHEL or Debian. I think I'm going Debian.
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 and 6 are deadest, do not use them.
Use the FAQ Luke

mark9090
Posts: 13
Joined: 2019/03/22 11:10:36

Re: Setting a Static IP

Post by mark9090 » 2019/03/22 19:05:44

ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp2s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 74:d4:35:e1:84:8c brd ff:ff:ff:ff:ff:ff
inet 192.168.1.67/24 brd 192.168.1.255 scope global dynamic enp2s0
valid_lft 75712sec preferred_lft 75712sec
inet 81.143.9.98/24 brd 81.143.9.255 scope global enp2s0:cp1
valid_lft forever preferred_lft forever
inet 81.143.9.99/24 brd 81.143.9.255 scope global secondary enp2s0:cp2
valid_lft forever preferred_lft forever
inet 81.143.9.100/24 brd 81.143.9.255 scope global secondary enp2s0:cp3
valid_lft forever preferred_lft forever
inet 81.143.9.101/24 brd 81.143.9.255 scope global secondary enp2s0:cp4
valid_lft forever preferred_lft forever
inet6 fe80::76d4:35ff:fee1:848c/64 scope link
valid_lft forever preferred_lft forever
ip link show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: enp2s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000
link/ether 74:d4:35:e1:84:8c brd ff:ff:ff:ff:ff:ff

Post Reply