Sharing Internet connection from your Linux

I want to share my Interent connection from my linux to another equipment.

First you have to enable NAT in your linux,
as root you must type:

# iptables -t nat -A POSTROUTING -o tun0 -j MASQUERADE

Then, logged as root, you have to enable IP forwarding.
There are two ways:

# sysctl -w net.ipv4.ip_forward=1

or

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

Now you have to configure in your other device the IP of your linux as default gateway.

And that’s all folks!

If you have problems with iptables and you want to remove all the rules write:

iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X
iptables -t mangle -F
iptables -t mangle -X
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s