最近要用Ubuntu Linux的iptables NAT功能來映射端口,但是接口機只有一個網卡,要實現既能訪問內網又能訪問外網,於是就要用到本文下面要說到的方法:
1、假設內網的IP信息為:
address 192.168.100.6
netmask 255.255.255.0
gateway 192.168.100.1
2、假設外網的IP信息為:
address 192.168.200.188
netmask 255.255.255.0
gateway 192.168.200.1
3、假設系統中網卡為:eth0
4、那麼,可以直接修改Ubuntu的IP配置文件:
#vim /etc/network/interfaces
然後參考下面的內容,相信懂Linux的童鞋都能看懂~
# This file describes the network interfaces available on your system# and how to activate them. For more information, see interfaces(5).# The loopback network interfaceauto loiface lo inet loopback# The primary network interfaceauto eth0iface eth0 inet staticaddress 192.168.100.6netmask 255.255.255.0#gateway 192.168.100.1# 下面是外網IP的設置auto eth0:1iface eth0:1 inet staticaddress 192.168.200.188netmask 255.255.255.0gateway 192.168.200.1修改好之後,wq!退出並保存,然後重啟網卡:
#/etc/init.d/networking restart
更多Ubuntu相關信息見Ubuntu 專題頁面 http://www.linuxidc.com/topicnews.aspx?tid=2