1

I've just assigned my CentOS machine with a static IP address using the /etc/sysconfig/network-scripts/ifcfg-eth0 which has the following lines and seems to be working

#eth0 config

DEVICE="eth0"
NM_CONTROLLED="yes"
ONBOOT=yes
HWADDR=*hardware address here*
TYPE=Ethernet
BOOTPROTO=static
NAME="System eth0"
IPADDR=10.0.0.66
NETMASK=255.255.255.0

when i use ifconfig I see that ip address is 10.0.0.66, however when I try to assign a gateway with /etc/sysconfig/network

NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=centosVM
GATEWAY=10.0.0.2

It doesn't seem to be working, when I use route -n I see that the gateway is 10.0.0.0

How do I set the gateway to work like my static IP?

UPDATE

I've just found that if I run dhclient it works. When I check the /etc/resolv.conf it has the nameserver 10.0.0.2 which I want.

I don't know why this fixes it but is there a way that I don't have to run dhclient every time? It doesn't seem right it should have the nameserver in the resolv.conf on boot?

  • Off topic: The commands ifconfig and route are being replaced by the ip command, i.e. use ip addr to view your IP address and ip route to view your routes (see ip(8)). – Manuel Faux Apr 4 '15 at 9:56
  • That is off topic but still helpful to know, thanks – TheLovelySausage Apr 4 '15 at 9:58
  • A assue you have already restarted your network using service network restart after changing the /etc/sysconfig/network file, right? – Manuel Faux Apr 4 '15 at 9:59
  • Yes, I even restarted the machine to make extra sure – TheLovelySausage Apr 4 '15 at 10:00
  • When you state "gateway" I assume you mean the default gateway (i.e. the gateway of 0.0.0.0/0), right? – Manuel Faux Apr 4 '15 at 10:00
0

Maybe no the solution to your problem but a workaround:

Add the gateway to your ifcfg-eth0 file instead of the network file:

#eth0 config

DEVICE="eth0"
MM_CONTROLLED="yes"
ONBOOT=yes
HWADDR=*hardware address here*
TYPE=Ethernet
BOOTPROTO=static
NAME="System eth0"
IPADDR=10.0.0.66
NETMASK=255.255.255.0
GATEWAY=10.0.0.2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.