Moxa KM-2430-T [33/52] Enabling nat at bootup

Moxa KM-2430-T [33/52] Enabling nat at bootup
ioPAC RTU Software RTU Communications
4-8
Enabling NAT at Bootup
In most real world situations, use a simple shell script to enable NAT when the ioPAC RTU controller boots up.
The following script is an example.
#!/bin/bash
# If you put this shell script in the /home/nat.sh
# Remember to chmod 744 /home/nat.sh
# Edit the rc.local file to make this shell startup automatically.
# vi /etc/rc.d/rc.local
# Add a line in the end of rc.local /home/nat.sh
EXIF=‘eth0’ #This is an external interface for setting up a valid IP address.
EXNET=‘192.168.126.0/24’ #This is an internal network address.
1. Insert modules.
# Here 2> /dev/null means the standard error messages will be dump to null device.
modprobe nf_tables 2> /dev/null
modprobe nf_conntrack 2> /dev/null
modprobe nf_conntrack_ftp 2> /dev/null
modprobe nf_conntrack_irc 2> /dev/null
modprobe iptable_nat 2> /dev/null
modprobe nf_nat_ftp 2> /dev/null
modprobe nf_nat_irc 2> /dev/null
2. Define variables, enable routing, and erase default rules.
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
export PATH
echo “1” > /proc/sys/net/ipv4/ip_forward
/bin/iptables -F
/bin/iptables -X
/bin/iptables -Z
/bin/iptables -F -t nat
/bin/iptables -X -t nat
/bin/iptables -Z -t nat
/bin/iptables -P INPUT ACCEPT
/bin/iptables -P OUTPUT ACCEPT
/bin/iptables -P FORWARD ACCEPT
/bin/iptables -t nat -P PREROUTING ACCEPT
/bin/iptables -t nat -P POSTROUTING ACCEPT
/bin/iptables -t nat -P OUTPUT ACCEPT
3. Enable IP masquerade.

Содержание

Скачать