1、打开内核ip转发
vi /etc/sysctl.conf
net.ipv4.ip_forward = 1
执行sysctrl -p生效
2、如果主机未启用防火墙,那么如下设置iptables
[[email protected] ~]
# iptables -F
[[email protected] ~]
# iptables -P INPUT ACCEPT
[[email protected] ~]
# iptables -P FORWARD ACCEPT
[[email protected] ~]
# iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
或者
iptables -t nat -A POSTROUTING -s ip -o eth0 -j MASQUERADE
[[email protected] ~]
# /etc/init.d/iptables save
[[email protected] ~]
# /etc/init.d/iptables restart
说明:
iptables -F
#清除原有的filter有中的规则
iptables -t nat -F
#清除原有的nat表中的规则
iptables -P FORWARD ACCEPT
#缺省允许IP转发
如果主机上启用了防火墙,需加上下面两句:
Code:
iptables -A FORWARD -s 192.168.122.0/24 -o eth0 -j ACCEPT
iptables -A FORWARD -d 192.168.122.0/24 -m state --state ESTABLISHED,RELATED -i eth0 -j ACCEPT
时间: 2024-11-23 04:12:35