1、vi /usr/local/sbin/firewall
#! /bin/bash# Project by Platinum, 2005-05-12"# Set Interface WANWAN_IP="外网卡地址"WAN_ETH="eth0"WAN_MASK="外网卡掩码地址"# Set Interface LANLAN_IP="内网卡地址"LAN_ETH="eth1"LAN_MASK="内网卡掩码地址"# Set MODE (LAN or ADSL)MODE="LAN"# Set default gatewayGATEWAY="网关地址"# Set managerMANAGER_IP="内网管理员IP"MANAGER_MAC="XX:XX:XX:XX:XX:XX"# Initialize modulesmodprobe ip_nat_ftpmodprobe ip_conntrack_ftpecho 1 > /proc/sys/net/ipv4/ip_forward# Initialize Interface LANifconfig $LAN_ETH $LAN_IP netmask $LAN_MASK# Initialize policyiptables -P INPUT DROPiptables -P FORWARD ACCEPTiptables -Fiptables -t nat -Fiptables -A INPUT -i lo -j ACCEPTiptables -A INPUT -i $LAN_ETH -s $MANGE_IP -m mac --mac-source $MANGE_MAC -m state --state NEW,RELATED,ESTABLISHED -j ACCEPTiptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPTcase "$MODE" in
LAN)
# Initialize Interface WAN
ifconfig $WAN_ETH $WAN_IP netmask $WAN_MASK
iptables -t nat -A POSTROUTING -s $LAN_NET -o $WAN_ETH -j SNAT --to $WAN_IP
;;
ADSL)
iptables -t nat -A POSTROUTING -s $LAN_NET -o ppp0 -j MASQUERADE
GATEWAY=`ifconfig ppp0|grep inet|awk '{print $3}'|awk -F: '{print $2}'`
;;esacip route replace default via $GATEWAY
2、chmod 700 /usr/local/sbin/firewall
只有root权限才能读写执行
3、echo "/usr/local/sbin/firewall" >> /etc/rc.local
让系统启动后自动执行脚本
4、reboot
重启系统
自己根据自己的情况改一下就可以了,应该不难懂
注意:
如果是直接设置IP上网,MODE选择LAN
如果是用PPPOE拨号上网,MODE选择ADSL,且保证在执行这个脚本之前已经拨号