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 want to connect a PC to the internet via my notebook, which is connected to a WLAN.

The setup should look like the following scheme: PC (eth0) -> Notebook (eth0) -> Notebook(wlan0) -> Router.
Both are running linux - arch on the notebook and funtoo on the PC.

Edit: So I tried rush's method and it didn't work for me, here is what I did:

PC:

ifconfig eth0 192.168.2.3
route add default gateway 192.168.2.2
nameserver 8.8.8.8 > resolv.conf

Notebook:

echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -o wlan0 -j SNAT --to-source 192.168.2.101

192.168.2.101 is the wlan0 IP address. I can't ping 192.168.2.2 (connect: Network is unreachable) and the connection doesn't seem to be working anymore on the notebook.

share|improve this question
add comment

1 Answer 1

up vote 6 down vote accepted

It's pretty easy. You need to connect PC to notebook. Configure eth0 on PC (set for example ip = 192.168.2.3 and default gateway 192.168.2.2 and dns server to 8.8.8.8). That's all you need to do on PC. On notebook you need to set up the internet connection as usual and configure eth0 with the following way: set ip address to 192.168.2.2, enable net forwarding with iptables.

Hope you're able to set up ip, gw and dns. To set up forwarding execute following script from root user:

#!/bin/sh
echo 1 > /proc/sys/net/ipv4/ip_forward
INET="wlan0"
INETIP="$(ifconfig $INET | sed -n '/inet addr/{s/.*addr://;s/ .*//;p}')"
iptables -t nat -A POSTROUTING -o $INET -j SNAT --to-source $INETIP

Watch out any specific iptables rules you're already have. To disable them you can execute before the script above:

iptables -F INPUT
iptables -F FORWARD
iptables -F OUTPUT
iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT
iptables -P FORWARD ACCEPT

And voila, you have the internet on PC.

share|improve this answer
    
Thank you for the reply, though I didn't manage to get it working. I will edit the topic. –  thpetrus Jul 4 '12 at 17:36
    
Ok, grabbed the wrong cable. Thanks! –  thpetrus Jul 4 '12 at 19:05
    
Worked like a charm for me. –  frant.hartm Feb 19 '13 at 19:57
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.