環境:

linux nat server:
eth0: x.x.x.x (外網ip)
eth1: 192.168.0.254 (內網ip)

執行以下兩個指令後,即可生效
# sysctl net.ipv4.ip_forward=1
# iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

觀察是否生效
/etc/init.d/iptables status 或是 service iptables status
...
Chain POSTROUTING (policy ACCEPT)
num target prot opt source destination
1 MASQUERADE all -- 0.0.0.0/0 0.0.0.0/0
...
 

如果要移除nat設定,請執行以下兩行指令
# sysctl net.ipv4.ip_forward=0
# iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE

但以上兩個指令重開機後,會回復到預設值
所以要寫進設定檔

# vi /etc/sysctl.conf
net.ipv4.ip_forward = 1

# /etc/init.d/iptables save 或是 service iptables save

個人電腦端設定:
只要把default gateway 指到192.168.0.254 即可

undefined
鳥哥的Linux私房菜:伺服器架設篇(第三版)(附光碟)

作者: 鳥哥  
出版社:碁峰  
 

arrow
arrow
    文章標籤
    linux firewall nat centos
    全站熱搜

    helloworld 發表在 痞客邦 留言(0) 人氣()