I'm currently at work and our wifi is down. I usually connect my desktop to the internet through eth0 and my laptop connects through wifi.

I have an extra port on the back of the desktop (eth1) and one on my laptop (eth0). I tried connecting a crossover cable between these two ports and bringing up a connection.

I set up a route to the desktop through my laptop and I can ping between the two machines but neither one will connect to the internet through desktop's eth0.

Any help is much appreciated =)

  • I assume that your desktop is running Linux (the most common unix variant). Network setup differ too much for a variant-agnostic question to make sense. – Gilles Apr 7 '11 at 19:55

Here's how you can set up IPv4 connection sharing manually on a Linux machine. On the router (the desktop), enable packet forwarding, set up masquerading on the Internet-facing interface (eth0), and use a private IP range on the local interface (eth1). Run these commands as root:

sysctl -w net.ipv4.ip_forward=1
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
ifconfig eth1 up broadcast netmask

On the laptop, you can set up a static address and route (eth0 being the wired interface):

ifconfig eth0 up broadcast netmask
route add -net gw

To avoid having to set up anything special on the laptop, you can run a DHCP server on the desktop. For example, install dnsmasq and enable its built-in DHCP server by editing /etc/dnsmasq.conf to include the following lines:


Note that Network Manager may interfere with these instructions. If you're running it on the router, either stop it or read the Ubuntu community Internet Connection Sharing page. (Network Manager on the laptop isn't a problem.)

If you want these settings to persist after a reboot, this is somewhat distribution-dependent. On Debian and derived distributions, put the following line in /etc/sysctl.d/connection-sharing.conf:


and the following lines in /etc/network/interfaces:

auto eth1
iface eth1 inet static
    post-up iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
  • +1. Would I be correct in summarizing these instructions as configuring the desktop as a router? An alternative to the OP would be to buy a router and hook both machines up to that. – Faheem Mitha Apr 7 '11 at 20:03
  • @Faheem: “On the router (the desktop) …” Strictly speaking, net.ipv4.ip_forward=1 and having two interfaces makes the desktop a router; the iptables command makes it a NAT appliance. – Gilles Apr 7 '11 at 20:09
  • @Gilles: I was not aware there was a precise definition of a router, and have not heard of a NAT appliance previously. Can you provide definitions or references? Thanks. – Faheem Mitha Apr 7 '11 at 20:19
  • @Faheem: 20 years ago, there were sharp differences, because network equipment tended to be expensive and differentiated. Nowadays the difference between a $50 appliance and a $500 appliance is not features but size (bandwidth, number of simultaneous connections, …). So the terminology has become quite blurred, and “router” is an acceptable generic term for many things. “NAT appliance” isn't established terminology. I suggest Wikipedia for generally accepted terminology. – Gilles Apr 7 '11 at 20:26
  • This worked flawlessly! The only change I made was mimicking desktop's resolv.conf on my laptop. I have some reading to do with iptables :) If you know off the top of your head, could the same be accomplished using the iproute2 utilities WITHOUT iptables? Thanks again for the help – flumpb Apr 8 '11 at 17:53

Use nice and easy to configure tool - shorewall.


I must agree with teZeriusz: Shorewall is a quick and easy way to configure and manage a router (Documentation here)

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.