I am trying to set up my Centos Server with two NICs as a router. eth0 is connected to the outside world and eth1 is connected to an Ubuntu client.

Here's eth0 on the server:


eth1 on the server:

IPADDR= # a free address on my network

My server has IPv4 packet forwarding turned on and my iptables only contains:

# iptables --table nat --append POSTROUTING --out-interface eth0 -j MASQUERADE
# iptables --append FORWARD --in-interface eth1 -j ACCEPT

My Ubuntu client has this in its /etc/network/interfaces

auto lo
iface lo inet loopback

iface eth0 inet dhcp

but I can't get an Internet connection from the server for my client. I can't even ping my server from the client:

$ ping
Destination Host Unreachable
  • Does your local network have a DHCP server? What is the output of ip addr show on the client and on the server? – Steven Monday Apr 8 '12 at 15:03
  • Hi Steven, ip addr show on the server showseth0 getting an IP of and eth1 getting an IP of which is what I would expect. BUT ip addr show does not show an IP address of the client – ale Apr 8 '12 at 15:14
  • so the client isn't getting an IP.. it guess it should be getting one via DHCP from the server? – ale Apr 8 '12 at 15:15
  • 2
    I suggest you get your server sorted out before worrying too much about the client. You have at least two problems on the server: (1) Your internal and external addresses have the same network address ( That's no good. Change one of them. (2) The external interface IP is non-routable (per RFC 1918). If your server is to be doing NAT for your internal network, you really want it to get a globally routable address on the external side. – Steven Monday Apr 8 '12 at 15:42
  • Once the server is good, then yes, you should probably install DHCP on it and configure it to hand out IPs to the local network. The Ubuntu client config looks mostly okay, except for the gateway line. Remove that line, since DHCP should be configuring that for clients. – Steven Monday Apr 8 '12 at 15:46

Am I the only one that noticed eth1 on the Centos server and eth0 on the client share the same IP, if the configs you posted are right. My habit is if I'm going to use a machine as a linux gateway, I usually use .1 as the last octet. so eth1 on the server would be, and eth0 on the client would be Of course, you do have to input the route for the gateway with route add default gw on the client. I'll look over your iptables settings again later, to check if I see anything.

With eth0 on the server using dhcp, if should grab everything it needs from the ISP, so there's nothing wrong there... (Oh, and you shouldn't need to do anything with routes or iptables to just ping the Centos router. Routes and iptables only come into play when trying to get to the outside world, so lets work on one thing at a time, and just get the client talking to the router first. That ip conflict is probably what's preventing that.) Good luck!!!


For starters, are you running DHCP on the Server?

Looking at the above, eth0 on the Server is the "inside" interface. The network config above suggests the inside interface on the server (aka router) use DHCP. Is there a reason for this config? It's usually better to set the gateway IP address to be static. Also, the Server eth0 ip address should be different than 192.168.0.x/24 (I'm assuming you're using a 24 bit mask here).

The client eth0 config (I'm assuming this is the only interface on the client and connects the client to the Server eth0 port via switch/hub/l2 device) also uses DHCP. Perhaps it's easier to use a static IP address for testing. Again, the client IP address should not be on the 192.168.0.x/24 subnet.

Lastly, the gateway on the client should be set to the eth0 ip address on the server.

The routing table on the Server should show both 192.168.0.x/24 and 192.168.1.x/24 (you could use any other private ip address) as directly connected with its default route pointing to the gateway IP address for that segment (not but the gw given to you by your ISP).


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.