首页 >
系统 >
linux
Ubuntu实现单网卡双IP的方法
时间:2014-05-28 23:14:08 点击: 来源: 作者:
最近要用Linux的iptables NAT功能来映射端口,
但是接口机只有一个网卡,要实现既能访问内网又能访问外网,
于是就要用到本文下面要说到的方法:
1、假设内网的IP信息为:
address 192.168.100.6
netmask 255.255.255.0 ...
最近要用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的童鞋都能看懂~
1 | # This file describes the network interfaces available on your system |
2 | # and how to activate them. For more information, see interfaces(5). |
4 | # The loopback network interface |
8 | # The primary network interface |
10 | iface eth0 inet static |
13 | #gateway 192.168.100.1 |
16 | iface eth0:1 inet static |
17 | address 192.168.200.188 |
修改好之后,wq!退出并保存,然后重启网卡:
1 | #/etc/init.d/networking restart |
OK,搞定。
”您可通过以下微信二维码,赞赏作者“
