首頁 > 軟體

Ubuntu實現單網絡卡雙IP的方法

2020-06-16 18:03:04

最近要用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


IT145.com E-mail:sddin#qq.com