Snippet Library
Browse | Submit A New Snippet | Create A Package
privnetnat | |
| Type: Full Script |
Category: UNIX Admin |
| License: GNU General Public License |
Language: Unix Shell |
Description: /etc/network/interface up-down command for setting up NAT automatically when an interface goes up. Ex: iface usb0 inet static address 192.168.76.254 network 192.168.76.0 netmask 255.255.255.0 broadcast 192.168.76.255 up /etc/network/privnetnat/privnetnat.sh down /etc/network/privnetnat/privnetnat.sh | |
Versions Of This Snippet:
| Snippet ID | Download Version | Date Posted | Author | Delete |
|---|---|---|---|---|
| 22 | 1.0 | 2008-10-08 16:39 | Pierre Neyron |
Download a raw-text version of this code by clicking on "Download Version"
Latest Snippet Version: 1.0
#!/bin/bash # # Copyright (C) 2008 Pierre Neyron <pierre.neyron_AT_free_DOT_fr> # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. # # Install: # Script file to be stored in /etc/network/privnetnat/privnetnat.sh # Need dhcp3-server pkg installed (as well as iptables of course) if [ "x$VERBOSITY" == "x1" ]; then env set -x fi [ -n "$IF_NETWORK" ] || IF_NETWORK=$(ipv4calc --network $IF_ADDRESS/$IF_NETMASK) DHCPDBIN=/usr/sbin/dhcpd3 DHCPDPID=/var/run/dhcpd-$LOGICAL-$IFACE.pid DHCPDCONF=/var/lib/dhcp3/dhcpd-$LOGICAL-$IFACE.conf DHCPDLEASES=/var/lib/dhcp3/dhcpd-$LOGICAL-$IFACE.leases case $MODE in start) cat <<EOF > $DHCPDCONF ddns-update-style none; default-lease-time 3600; max-lease-time 7200; log-facility local7; subnet $IF_NETWORK netmask $IF_NETMASK { range ${IF_NETWORK/%0/10} ${IF_NETWORK/%0/20}; option routers $IF_ADDRESS; option domain-name-servers $(grep nameserver /etc/resolv.conf | cut -d\ -f2 | xargs | sed 's/ /, /g'); } EOF touch $DHCPDLEASES start-stop-daemon --start --pidfile $DHCPDPID --exec $DHCPDBIN -- -cf $DHCPDCONF -lf $DHCPDLEASES -pf $DHCPDPID -q $IFACE echo 1 > /proc/sys/net/ipv4/ip_forward iptables -t nat -I POSTROUTING 1 -s $IF_NETWORK/$IF_NETMASK -d ! $IF_NETWORK/$IF_NETMASK -j MASQUERADE iptables -I FORWARD 1 -i $IFACE -s $IF_NETWORK/$IF_NETMASK -j ACCEPT ;; stop) start-stop-daemon --stop --quiet --pidfile $DHCPDPID rm -f "$DHCPDPID" iptables -t nat -D POSTROUTING -s $IF_NETWORK/$IF_NETMASK -d ! $IF_NETWORK/$IF_NETMASK -j MASQUERADE iptables -D FORWARD -i $IFACE -s $IF_NETWORK/$IF_NETMASK -j ACCEPT echo 0 > /proc/sys/net/ipv4/ip_forward ;; esac;
Submit a new version
You can submit a new version of this snippet if you have modified it and you feel it is appropriate to share with others..

