Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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 =)

share|improve this question
    
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
add comment

3 Answers

up vote 2 down vote accepted

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 10.1.1.1 broadcast 10.1.1.255 netmask 255.255.255.0

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

ifconfig eth0 up 10.1.1.2 broadcast 10.1.1.255 netmask 255.255.255.0
route add -net 0.0.0.0/0 gw 10.1.1.1

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:

except-interface=eth0
dhcp-range=10.1.1.128,10.1.1.254,24h

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:

net.ipv4.ip_forward=1

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

auto eth1
iface eth1 inet static
    address 10.1.1.1
    broadcast 10.1.1.255
    netmask 255.255.255.0
    post-up iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
share|improve this answer
    
+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 –  kisplit Apr 8 '11 at 17:53
show 2 more comments

Use nice and easy to configure tool - shorewall.

share|improve this answer
add comment

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.