首页 > 系统 > 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).
3  
4 # The loopback network interface
5 auto lo
6 iface lo inet loopback
7  
8 # The primary network interface
9 auto eth0
10 iface eth0 inet static
11 address 192.168.100.6
12 netmask 255.255.255.0
13 #gateway 192.168.100.1
14 # 下面是外网IP的设置
15 auto eth0:1
16 iface eth0:1 inet static
17 address 192.168.200.188
18 netmask 255.255.255.0
19 gateway 192.168.200.1

修改好之后,wq!退出并保存,然后重启网卡:

1 #/etc/init.d/networking restart

OK,搞定。

”您可通过以下微信二维码,赞赏作者“
 
 
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表
推荐资讯
linux服务器同步互联网时间
linux服务器同步互联
亚马逊云lightsail服务器使用教程 | 亚马逊云lightsail使用指南
亚马逊云lightsail服
hostdare 4折优惠,直接降价60% 美国洛杉矶低至 $10.4/年 768M内存/1核/10gNVMe/500g流量
hostdare 4折优惠,直接
六类网线cat6a和cat6e的区别
六类网线cat6a和cat6e
相关文章
栏目更新
栏目热门

关于我们 | 广告服务 | 联系我们 | 网站地图 | 免责声明 | WAP | RSS


Copyright © 运维之家 2013-2023