Internet sharing to a subnet (with NAT): iptables script

There is a script you can use for Internet sharing for an IP or a subnet with NAT:

#!/bin/bash
echo -e "\e[6;32mConfiguring iptables..\e[0;0m"

# replace ppp0 to your external interface name
ext_if = "ppp0"

echo 1 > /proc/sys/net/ipv4/ip_forward
#uncomment the string for sharing to the whole local net
#iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -o $ext_if -j MASQUERADE

#sharing to 192.168.1.2 ip:
iptables -t nat -A POSTROUTING -s 192.168.1.2 -o $ext_if -j MASQUERADE

Save the script to /etc/init.d/ directory. Name it, for example, net_share and make the script executable:

sudo chmod a+x /etc/init.d/net_share

Activate Internet sharing:

sudo /etc/init.d/net_share

To put the script in startup do the following:

sudo update-rc.d net_share defaults






Got a comment?

captcha =

Categories

  1. System (20)
    1. FreeBSD (5)
    2. Linux (9)
  2. Email (2)
  3. DNS (2)
  4. Databases (1)
  5. WebServer (27)
 
Copyright © 2012-2015 HowToUnix - *nix Howtos and Tutorials
All Rights Reserved.