Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

setting up 2 network interfaces on linux laptop to share internet conn

Status
Not open for further replies.

JoBlink

Technical User
May 28, 2004
38
US
Hi!

I read for 4 days various articles on it, but being a networking and Linux Noob, could not make it work. I am out of ideas with no hope of making it on my own, so please, HELP!

I am trying to set up a laptop with linux server as a gteway/router. Laptop needs Public IP because some app does not work behind NAT. DMZ did not work, so I am setting it up to connect directly to modem and pass through internet connection to WiFi router

Laptop connects to Internet modem with USB (eth2) port, and to WiFi Router with LAN (eth0) port. In this setup, eth2 connects to internet, but eth0 is not connecting to WiFi router - Ping returns "Destination Host Unreachable."

There is no bridge and no DHCP on laptop.

When connected to LAN as Computer 3 (192.168.0.202) (eth0) it is working fine.

eth0 and eth2 are as follows
Eth0
address 192.168.0.202
netmask 255.255.255.0
network 192.168.0.0
gateway 192.168.0.1 - WiFi Routeer

Eth2
Address 68.37.253.151
netmask 255.255.252.0
Gateway 68.37.136.1


My current LAN setup:
Internet Modem -> WiFi Router (192.168.0.1)
IP Address : 68.37.253.151
Subnet Mask : 255.255.252.0
Default Gateway :68.37.136.1
DNS : 4.2.2.2 8.8.8.8
-> -> ->Computer 1 (192.168.0.100), Computer 2 (192.168.0.101), VoIP Phone (192.168.0.102)

I am trying to set up:

Internet Modem -> Linux (Ubuntu 8.04 LTE) server ->
-> WiFi Router (192.168.0.1) -> -> -> Computer 1 (192.168.0.100), Computer 2 (192.168.0.101), VoIP Phone (192.168.0.102)

Kernel IP routing table behind router reads

Destination Gateway Genmask Flags MSS Window irtt Iface
192.168.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
0.0.0.0 192.168.0.1 0.0.0.0 UG 0 0 0 eth0

When eth2 is on, (ahead of router) it reads
192.168.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
0.0.0.0 192.168.0.1 0.0.0.0 UG 0 0 0 eth0
67.37.252.0 0.0.0.0 255.255.254.0 U 0 0 0 eth2

I edited file /etc/init.d/firewall.sh

iptables --table nat --append POSTROUTING --out-interface eth2 -j MASQUERADE
iptables --append FORWARD --in-interface eth0 -j ACCEPT

Edited /etc/sysctl.conf
to enable net.ipv4.ip_forward=1

Thank you for reading.




 
I'd install Webmin, setup the two interfaces as you have, then allow routing between interfaces. (All in Webmin under "Networking")

Make sure there is a route where the default gateway is 68.37.136.1

Finally, make the default gateway in your wireless router (which won't be routing anything but will act as the DHCP server) 192.168.0.202 with the 2 DNS servers you mentioned.

Don't plug anything into the WAN port of your wireless router - everything should be plugged into the LAN side.

-----------------------------------
Telephone & computer wiring/Cat 5E/Cat 6/Fibre Optic cabling in Calgary, AB
 
To share an internet connection in Linux there are two things that are required.
1 - enable IPV4 Forwarding. This is set in a /proc file, which is defaulted as not persistent across reboots. You will need to account for this in your configuration.

2 - Use IPTables to perform the NAT between the interfaces. The easiest way to do this is with the MASQUERADE directive.

This article seems to explain the steps clearly:
Also, beware that you only have ONE default gateway. Typically this will be on your Internet access interface and the other interfaces will simply route the local subnet.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top