I have a Linux (Ubuntu 12.04) PC connected to the internet with a Greenpacket WiMax USB modem. I want to share the Internet connection with another computer running Windows 7 Home Premium, connected to the Linux PC over a LAN. Is this possible? How? Is the reverse possible instead (connecting the internet to the Windows computer and sharing it with Linux)?

  • Did it work? Do you need any more help? – Christian Jun 15 '12 at 9:20
  • Thanks. You are so helpful. But sorry, I have no time to do this right now. I will comment as soon as possible. – muntasir2000 Jun 20 '12 at 12:07

You need to set up NAT on the Linux box. There are numerous howtos on the Net when you search for NAT and iptables, maybe including the distro you use. Here is a howto for Debian which should work on other distros as well: http://debianclusters.org/index.php/NAT_with_IPTables

Here are some lines that come from a German Ubuntu howto:

sysctl -w net.ipv4.ip_forward=1
iptables -A FORWARD -o eth0 -s -m conntrack --ctstate NEW -j ACCEPT
iptables -A FORWARD -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

Put them somewhere, where they are executed at startup (/etc/rc.local or you put "up" in front of every line and put the whole thing into /etc/network/interfaces) and replace eth0 by the network device that connects to the Internet and eth1 by the one that goes to your LAN.

You might also have to tell your Windows box some name servers (DNS) manually if you don't want to set up bind on your Linux box. And I trust you don't need or already have a DHCP server in your LAN.


The question asks,

Is the reverse possible instead (connecting the Internet to the Windows computer and sharing it with Linux)?

Here's how you can share your Internet connection from Windows to Linux.

On Windows,

  • Make sure internet sharing is enabled.

    • Go to Control Panel, find the network connection, then right-click on the internet adapter and click "Properties".
    • Click "Advanced".
    • Right there click the radio button to enable Internet sharing.
  • On Windows 7:

    • Go to Control Panel → "Network and Sharing Center".  (You may need to go through "Network and Internet" to get there.)
    • Clink on "Change adapter settings".
    • Right-click on the network adapter and click "Properties".  Enter an administrator password, if asked.
    • Click on the "Sharing" tab and enable sharing.

On Linux,

With root (sudo or su) privilege,

  1. Type this to set the default gateway:

    route add default gw x.x.x.x

    (Note: replace x.x.x.x by the Windows host's local IP address.  You can find it by typing: ipconfig -all in the Windows Command Prompt.)

  2. Next type this to set the DNS:

    echo "nameserver y.y.y.y" > /etc/resolv.conf

    (Note: replace y.y.y.y by the DNS server address on Windows.  You can find it by typing: ipconfig -all in the Windows Command Prompt.)

In this scenario, Windows is already connected to the Internet.  After all the setup, you can try now to use the Internet from Linux.  The Linux and Windows hosts should be able to use the Internet simultaneously.

  • 1
    -1: he wants to do the opposite (share the internet from the Linux box to the Windows box). – Renan Nov 30 '12 at 22:11
  • 1
    but he also interested to do the reverse. here is i am quote his question: Is the reverse possible instead (connecting the internet to the Windows computer and sharing it with Linux)? – rnlsgh Dec 2 '12 at 20:17
  • 1
    if you want to share internet from Linux to Windows, I think the answer above given by Christian is basically correct after replacing this: iptables -A FORWARD -o eth0 -s -m conntrack --ctstate NEW -j ACCEPT with this: iptables -A FORWARD -i eth1 -s -m conntrack --ctstate NEW -j ACCEPT (note:I am only correcting the typos: -o eth0, replace by -i eth1). plus on Windows side you have to set the gateway with Linux IP and DNS address with the ISP's DNS. – rnlsgh Dec 2 '12 at 20:51
  • but if it doesn't work maybe there is conflict on iptables rules. in this case before those 4 command lines maybe you need to erase all previous iptables rules by type this: (1)iptables -F (2) iptables -t nat -F (3)iptables -X (4)iptables -t nat -X – rnlsgh Dec 3 '12 at 7:05
  • 1
    after all 8 command lines you need to save the settings by type: iptables-save. – rnlsgh Dec 3 '12 at 7:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.