Linux tips
Simple guide to share Internet connection on UBUNTU
June 11, 2012
0

Hello to everyone,

What I’d like to explain today is how to share your Internet connection with other PC accessing your net, using  Ubuntu. First of all you need to know which is the network interface you’re using. So open the terminal and write:;

 

route -n | grep "0.0.0.0" | grep UG | awk '{print $8}'

Now what you need to do is grabbing root access using

sudo -s -H

At this point what we are going to do is setting up  NAT (Network Address Translation) masquerading on Iptables using this command(we are pretending that the network interface used is ppp0):

iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE

Now check if everything went well using:

iptables -t nat -L

To check it, find in the answer the following lines:

Chain POSTROUTING (policy ACCEPT)
target     prot opt source               destination
MASQUERADE  0    --  anywhere             anywhere

This means that the rule has been accepted and it will be applied to all source address (source anywhere) going to everywhere (destination anywhere).

The final step is allowing routing on our machine, enabling ip_forwarding with:

echo 1 > /proc/sys/net/ipv4/ip_forward

All of these modifications are temporary and we need to make them permanent, se follow these steps

To save the rule:


  1. To save the rule:
    iptables-save > /etc/iptables-shared-connection.rule
  2. To restore the rule:
    iptables-restore < /etc/iptables-shared-connection.rules
  3. Create the script:
    cd /etc/network
    iptables-save > iptables-shared-connection.rules
    touch activate-shared-connection
    chmod u+x activate-shared-connection
    gedit activate-shared-connection
  4. Modify the script:
    iptables-restore < /etc/iptables-shared-connection.rules
  5. Edit interfaces file:
    gedit interfaces
  6. Add at the end of the file and save:
    pre-up /etc/network/activate-shared-connection

And you’ve done!!!  You just shared your Internet connection through your local network. The last step is to configure on other machines the correct gateway; first of all grab your local IP address using:

ifconfig

Look for the kind of connection you’re using (eth0/1 if cable, wlan0 if wireless), take your IP address and use it on other machines network configuration settings as the main gateway.

And that’s all!!

Enjoy!!

 

Leave a Reply

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close