Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a problem with NAT configuration. I made my laptop to be a router, using Ubuntu 12.04. In the terminal, I typed:

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

but the client still has not been able to connect to the Internet, when interfacing the router (my laptop) to a client using a LAN cable. But the client is able to ping the router.

How can I solve the problem?

share|improve this question

Your NAT firewall rule is OK but by default ubuntu is not forwarding packets so you need to enable that with:

echo 1 > /proc/sys/net/ipv4/ip_forward

To make it automatic, you can use a script like this (save in /etc/init.d/your-script):

#!/bin/sh
# turn ip_forward on/off

case "$1" in
'start')
        echo 1 > /proc/sys/net/ipv4/ip_forward
        ;;
'stop')
        echo 0 > /proc/sys/net/ipv4/ip_forward
        ;;
*)
        echo "Usage: $0 { start | stop }"
        ;;
esac
exit 0

And make it executable and run on boot with:

sudo chmod +x /etc/init.d/your-script
sudo update-rc.d your-script defaults

To enable: sudo /etc/init.d/your-script start and sudo /etc/init.d/your-script stop to disable.

UPDATE: As Paul commented, if you prefer, to make it permanent (or if you feel comfortable editing the conf file to turn this feature on/off) you can modify /etc/sysctl.conf and uncomment the line with net.ipv4.ip_forward=1 to enable and comment out to disable.

share|improve this answer
3  
Please don't make a script to do this, just edit /etc/sysctl.conf and uncomment net.ipv4.ip_forward=1 – Paul May 23 '12 at 0:36
    
Sure for permanent config, sysctl.conf is better but that depends on the use, if he wants to be able to turn it on and off (as it is a laptop and he may not want to forward everywhere), a script is easier (and he has the option to not enable it on boot too if he wants). – laurent May 23 '12 at 0:38
    
Sure - for completeness, why not edit and include the sysctl option as well as the script option. – Paul May 23 '12 at 0:49
    
lol sure I was doing that now!! thanks – laurent May 23 '12 at 0:51
    
I have tried but the client still can't connect to the internet – Elpin Permana May 23 '12 at 11:14

You must log in to answer this question.

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