Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'm setting up a NAT for a connected router to my laptop using the following command (IP forwarding is enabled):

sudo iptables -t nat -A POSTROUTING -s 192.168.47.0/24 -o eth0 -j MASQUERADE

So basically I have a eth0 which is my laptop's LAN, and a USB-CAT5 -based connection from my laptop to a wireless router, which is eth1. And I am assigning a static IP to my eth1 interface (i.e. connected to the wireless router) using the following command:

sudo ifconfig eth1 192.168.47.1 netmask 255.255.255.0 up

And I run ifconfig to make sure eth1 has this IP address:

eth0  Link encap:Ethernet  HWaddr 28:d2:44:77:39:0e  
      inet addr:129.46.79.72  Bcast:129.46.79.255  Mask:255.255.254.0
      inet6 addr: 2002:c023:9c17:118:f5ea:ed5a:6c19:138d/64 Scope:Global
      inet6 addr: fe80::2ad2:44ff:fe77:390e/64 Scope:Link
      inet6 addr: 2002:c023:9c17:118:2ad2:44ff:fe77:390e/64 Scope:Global
      UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
      RX packets:289511 errors:0 dropped:324 overruns:0 frame:0
      TX packets:103659 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:1000 
      RX bytes:87784569 (87.7 MB)  TX bytes:26739445 (26.7 MB)
      Interrupt:20 Memory:f0600000-f0620000 

eth1  Link encap:Ethernet  HWaddr 00:50:b6:0a:4c:5e  
      inet addr:192.168.47.1  Bcast:192.168.47.255  Mask:255.255.255.0
      UP BROADCAST MULTICAST  MTU:1500  Metric:1
      RX packets:2268 errors:0 dropped:0 overruns:0 frame:0
      TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:1000 
      RX bytes:104328 (104.3 KB)  TX bytes:0 (0.0 B)

The router's settings has been setup. My problem is that when I'm connected to the router, I don't have any internet connection. Can someone help me with that?

share|improve this question

2 Answers 2

You also need to tell the machine that's acting as a router to forward the packages it receives and configure the default gateway, use this command:

sudo sysctl net/ipv4/ip_forward=1

To add a default gateway, also add:

sudo route add -net default gw X.X.X.X

Where X.X.X.X is the IP of your wireless router.

share|improve this answer
    
is it different than echo 1 > /proc/sys/net/ipv4/ip_forward , which enables IP_forwarding?! –  Tina Jasmin May 30 at 21:52
    
It's the same order, but using sysctl. The result is the same, yes. –  darent May 30 at 21:54
    
So, yeah...As I said, it is already enabled. –  Tina Jasmin May 30 at 21:55
    
Try also enabling the gateway, see if that's the problem. –  darent May 30 at 21:57
    
So xxx should be the static IP I've been trying to assign, right? 192.168.47.1 –  Tina Jasmin May 30 at 21:58

Test this:

sudo su

iptables -F

iptables -A INPUT -i lo -j ACCEPT

iptables -A INPUT -s 192.168.47.0/24 -i eth1 -j ACCEPT

iptables -t  nat  -A POSTROUTING -s 192.168.47.0/24 -o eth0 -j MASQUERADE

echo 1 > /proc/sys/net/ipv4/ip_forward  
share|improve this answer
    
Well; no changes. One thing which I'm not sure about is that when I click on the network icon near the clock, for eth1's wired network, it shows disconnected! However ifconfig shows it as UP ! –  Tina Jasmin May 30 at 22:16

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.