0

I am very new to linux routing. Although I understand it conceptually, the actual route commands escape me. I have tried ip route and ip rule on my own, but they didn't work. Hence posting a question here.

Here's my current setup. Centos server with two NICs

eth0 (external and open to the internet)
- static IP: 192.168.13.10
- GW: 192.168.13.1
eth1 (internal private)
- static IP: 192.168.15.10
- GW: Not defined yet. (as I would imagine 192.168.13.1 to be catch all)

Centos client with one NIC

eth0
- Static IP: 192.168.15.200
- GW: 192.168.15.10

Firstly, I would like the Centos client to be able to connect to the internet only via the Centos Server. I know I am missing some form of routing table entry for the above to work. Could someone point that out for me?

Secondly, I would like the Centos client to acquire the IP address from the Centos server. I have dhcpd installed on the Centos server. So just changing the booproto in the ifcfg-eth0 script (from static to dhcp) be enough or is there any routing changes required on the centos client?

2
  • I don't think any routing table entries are required as DHCP should give it all it needs (on the same subnet). You do need a way for the server to direct traffic to its external interface though (like with iptables).
    – Nathan C
    Nov 26, 2014 at 16:04
  • Okay. So what firewall rule/s do I need? Nov 26, 2014 at 19:57

2 Answers 2

0

John is right, but some optional firewall rules are not optional, but required. To route the traffic to the internet you need IP forwarding, as explained by John, but you will also need IP masquerading (NAT).

Edit /etc/sysctl.conf and add

net.ipv4.conf.default.forwarding=1

Restart the network service by

service network restart

Now you'll need the iptables "NAT" rule:

iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

I'm not too familiar with CentOS, but maybe you need to restart an iptables service or issue iptables save (or both).

1
  • Doing the above steps worked for me, so going to choose this as the answer, although John had valid points as well. So thanks John. Dec 1, 2014 at 20:54
0

Your setup as it exists is correct but incomplete. You need to enable packet forwarding on the CentOS server and optionally some sort of firewall to block unwanted traffic. Your clients are already attempting to go through the server to get to the internet, they're simply unable to do so until you enable packet forwarding at a minimum.

DHCP is a separate issue, but again, there are no routing changed required for the clients - if the DHCP server gives the client the same IP information it has now, it will work as you expect.

2
  • Thanks. let me try to enable it and will get back to you. But I was just concerned about the GW information for eth1 on the centos server. Do I need specify a default GW using route or in the network script? or is my assumption of 'catch all' correct? Nov 26, 2014 at 15:13
  • No, there is only one "default gateway" per machine. Adding a GW to the eth1 config will break things. Your assumption of "catch-all" is correct.
    – John
    Nov 26, 2014 at 15:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .