Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

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

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

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


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 ( (eth0) it is working fine.

eth0 and eth2 are as follows
gateway  - WiFi Routeer


My current LAN setup:
Internet Modem -> WiFi Router (
IP Address :
Subnet Mask :
Default Gateway :
DNS :  
-> -> ->Computer 1 (, Computer 2 (, VoIP Phone (

I am trying to set up:

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

Kernel IP routing table behind router reads

Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface   U  0 0       0 eth0         UG 0 0       0 eth0

When eth2 is on, (ahead of router) it reads   U   0 0       0 eth0         UG  0 0       0 eth0   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.


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

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

Finally, make the default gateway in your wireless router (which won't be routing anything but will act as the DHCP server) 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

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

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: http://www.revsys.com/writings/quicktips/nat.html

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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close