linux下共享上网设置 shell script

来源:百度文库 编辑:神马文学网 时间:2024/04/30 10:58:25
linux下共享上网设置
erqie 发表于 2005-10-9 13:34:00
使用固定internt IP
#!/bin/sh
# define
# EXT: 外部
# INT: 内部
# 定义接口
# define interface
EXT_IF="eth1"
INT_IF="eth0"
EXT_IP="202.96.0.2"
# 定义 iptables 执行文件
# define iptables exec
IPTABLES="/usr/sbin/iptables"
# 清空所有规则
# flush all the rules in the filter and nat tables.
$IPTABLES -F
$IPTABLES -t nat -F
$IPTABLES -t mangle -F
# 删除所有链
# erase all chains that‘s not default in filter and nat table.
$IPTABLES -X
$IPTABLES -t nat -X
$IPTABLES -t mangle -X
# 加载必要模块
# load modules
/sbin/depmod -a
/sbin/modprobe ip_tables
/sbin/modprobe ip_conntrack
/sbin/modprobe iptable_filter
/sbin/modprobe iptable_nat
/sbin/modprobe ipt_limit
/sbin/modprobe ipt_state
/sbin/modprobe ip_conntrack_ftp
# 激活 ip 转发
# enable ip forward
echo "1" > /proc/sys/net/ipv4/ip_forward
# nat 表
# nat table
$IPTABLES -t nat -A POSTROUTING -o $EXT_IF -j SNAT --to-source $EXT_IP
使用adsl拨号
#!/bin/sh
# define interface
EXT_IF="ppp0"
INT_IF="eth0"
# define iptables exec
IPTABLES="/usr/sbin/iptables"
# flush all the rules in the filter and nat tables.
$IPTABLES -F
$IPTABLES -t nat -F
$IPTABLES -t mangle -F
# erase all chains that‘s not default in filter and nat table.
$IPTABLES -X
$IPTABLES -t nat -X
$IPTABLES -t mangle -X
# load modules
/sbin/depmod -a
/sbin/modprobe ip_tables
/sbin/modprobe ip_conntrack
/sbin/modprobe iptable_filter
/sbin/modprobe iptable_nat
/sbin/modprobe ipt_limit
/sbin/modprobe ipt_state
/sbin/modprobe ip_conntrack_ftp
# enable ip forward
echo "1" > /proc/sys/net/ipv4/ip_forward
# nat table
$IPTABLES -t nat -A POSTROUTING -o $EXT_IF -j MASQUERADE