Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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)?

share|improve this question
    
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
add comment

2 Answers 2

up vote 3 down vote accepted

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 192.168.0.0/16 -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.

share|improve this answer
add comment

You can share internet connection from Windows to Linux. In windows make sure internet sharing is enabled. Go to control panel, find network connection, and then right click on internet adapter. Click properties and advance. Right there click radio button to enable internet sharing.

On Linux side, with root privilege,

1.type this on terminal to set default gateway:

route add default gw x.x.x.x

(note: replace x.x.x.x by windows local IP, you can find it by typing: ipconfig -all, in Windows command shell).

  1. next type this on terminal to set the DNS:
echo "nameserver y.y.y.y" > /etc/resolv.conf

(note: replace y.y.y.y by DNS address on Windows, you can find it by typing: ipconfig -all, in Windows command shell)

In this scenario, Windows is already connected to internet. After all the set up you can try now to use the internet from Linux. Now both Linux and Windows should be able to use internet simultaneously.

share|improve this answer
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
    
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
    
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 192.168.0.0/16 -m conntrack --ctstate NEW -j ACCEPT with this: iptables -A FORWARD -i eth1 -s 192.168.0.0/16 -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
    
after all 8 command lines you need to save the settings by type: iptables-save. –  rnlsgh Dec 3 '12 at 7:16
add comment

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.