Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save binarytemple/5e64d06a0afe0cc2f585 to your computer and use it in GitHub Desktop.
Save binarytemple/5e64d06a0afe0cc2f585 to your computer and use it in GitHub Desktop.

CentOS 6.7 - configuring networking where the gateway is on a different subnet

If I were to have configured routing from the command line (or an init script) I would have entered the following:

route add -net 172.27.209.0/24 eth0
route add -net 172.27.211.0/24 eth0
route add default gw 172.27.211.254

In this case the :

  • Host IP address is '172.27.209.217/24' on eth0
  • Gateway IP address is '172.27.211.254'
  • The machine needs to also talk to machines in the '172.27.211.0/24' subnet

But this is CentOS... Lets take a look at what needs to be configured:

# cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=sekrit001
GATEWAY=172.27.211.254

# cat /etc/sysconfig/network-scripts/ifcfg-eth0 
DEVICE=eth0
HWADDR=00:50:56:A1:76:C8
TYPE=Ethernet
UUID=db502574-6359-4d8b-ba44-848a25701cf6
ONBOOT=yes
BOOTPROTO=static
IPADDR=172.27.209.217  
NETMASK=255.255.255.0

# cat /etc/sysconfig/network-scripts/route-eth0 
172.27.211.0/24 dev eth0
default via 172.27.211.254 

After this, execute service network restart and everything works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment