I have a cluster consists of several RedHat_7 PCs. The master node connects to two networks(Internal and Internet). I used to utilizing NAT to provide Internet service for all the computers.
For some reason, this method doesn't work now. The NAT cmds shows below.
sudo iptables -t nat -A POSTROUTING -s 192.168.10.0/24 -o em4 -j MASQUERADE
sudo sysctl -w net.ipv4.ip_forward=1
and, usually, I have to add a default route,
sudo route add default gw 'my_gateway' em4
Then, I can surf the Internet. However, it works only for a couple of minutes, so I have to execute these cmds periodically.
route -n gets below:
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.10.10 0.0.0.0 UG 100 0 0 em1
0.0.0.0 X.X.X.1 0.0.0.0 UG 101 0 0 em4
192.168.10.0 0.0.0.0 255.255.255.0 U 100 0 0 em1
X.X.X.0 0.0.0.0 255.255.224.0 U 0 0 0 em4
X.X.X.0 0.0.0.0 255.255.224.0 U 100 0 0 em4
and ip route show gets below:
default via 192.168.10.10 dev em1 proto static metric 100
default via X.X.X.1 dev em4 proto static metric 101
192.168.10.0/24 dev em1 proto kernel scope link src 192.168.10.10 metric 100
X.X.X.0/19 dev em4 proto kernel scope link src MY_IP
X.X.X.0/19 dev em4 proto kernel scope link src MY_IP metric 100
if I execute the route add cmd, changes show below:
0.0.0.0 X.X.X.1 0.0.0.0 UG 0 0 0 em4
default via X.X.X.1 dev em4
and after several minutes, these changes are gone. I have some questions.
- why the default route is deleted after some time?
- the static label in ip route show means what?
- how to solve the whole problem?
Thanks for any help.
EDIT
The configuration file for these two file are shown below:
/etc/sysconfig/network-scripts/ifcfg-em1
TYPE=Ethernet
BOOTPROTO=none
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=no
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
NAME=em1
UUID=MYUUID
ONBOOT=yes
HWADDR=MYMAC
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPADDR=192.168.10.10
PREFIX=24
GATEWAY=192.168.10.10
/etc/sysconfig/network-scripts/ifcfg-em4
TYPE=Ethernet
BOOTPROTO=dhcp
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=no
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
NAME=em4
UUID=MYUUID
ONBOOT=yes
HWADDR=MYMAC
PEERDNS=yes
PEERROUTES=yes
Best Answer
It looks like you might be using DHCP for your internal network, and your DHCP config seems to include a default route.
Your issue is basically down to these two entries:
Your em1 default route has a slightly lower cost than your em4 default gateway, meaning the route via 192.168.10.10 is being preferred.
For the one ('master') node providing connectivity with the internet, your best bet is to set a static IP (the master node is presumably a gateway, so a static IP would I think make sense), and not use DHCP.
You could also create a host-specific configuration in DHCP for your master node, but I suspect making the master node static is simpler.