Chinaunix首页 | 论坛 | 博客
  • 博客访问: 9168450
  • 博文数量: 1669
  • 博客积分: 16831
  • 博客等级: 上将
  • 技术积分: 12594
  • 用 户 组: 普通用户
  • 注册时间: 2011-02-25 07:23
个人简介

柔中带刚,刚中带柔,淫荡中富含柔和,刚猛中荡漾风骚,无坚不摧,无孔不入!

文章分类

全部博文(1669)

文章存档

2023年(4)

2022年(1)

2021年(10)

2020年(24)

2019年(4)

2018年(19)

2017年(66)

2016年(60)

2015年(49)

2014年(201)

2013年(221)

2012年(638)

2011年(372)

分类: 系统运维

2017-02-05 11:27:59

 

Linux操作系统单网卡双IP的设置

 7387人阅读 评论(0)  举报
 分类:
linux(102) 

Centos5下:

1、配置第一个IP地址:

    [root@Linux root]#cd /etc/sysconfig/network-scripts 
    [root@Linux network-scripts]#vi ifcfg-eth0 
    DEVICE=eth0 
    BOOTPROTO=static 
    BROADCAST=192.168.80.255 //*广播地址*// 
    IPADDR=192.168.80.189 //*第一个IP地址*// 
    NETMASK=255.255.255.0 //*网络掩码*// 
    NETWORK=192.168.80.0 //*所在网段*// 
    ONBOOT=yes 
    :wq //*保存退出*//

    2、复制第一个IP地址配置文件为第二个IP地址配置文件,并修改里面的IP地址:

    [root@Linux network-scripts]#cp ifcfg-eth0 ifcfg-eth1 
    [root@Linux network-scripts]#vi ifcfg-eth1 
    DEVICE=eth0:1 //用eth0也可以,也能通,但是重启网卡时会提示eth0 file existed! 
    BOOTPROTO=static 
    BROADCAST=192.168.80.255 //*广播地址*// 
    IPADDR=192.168.80.199 //*第二个IP地址*// 
    NETMASK=255.255.255.0 //*网络掩码*// 
    NETWORK=192.168.80.0 //*所在网段*// 
    ONBOOT=yes 
    :wq //*保存退出*//

3、重启网卡: 
    [root@Linux network-scripts]#service network restart 
或: 
    [root@Linux network-scripts]#ifdown eth0 
    [root@Linux network-scripts]#ifup eth0 
或 
    [root@Linux network-scripts]#ifconfig eth0 down 
    [root@Linux network-scripts]#ifconfig eth0 up

方法二:在配置第二个IP地址的时候有变化其他

1、配置第一个IP地址以及网关:

[root@Linux root]#cd /etc/sysconfig/network-scripts 
    [root@Linux network-scripts]#vi ifcfg-eth0 
    DEVICE=eth0 
    BOOTPROTO=static 
    BROADCAST=192.168.80.255 //*广播地址*// 
    IPADDR=192.168.80.189 //*第一个IP地址*// 
    NETMASK=255.255.255.0 //*网络掩码*// 
    NETWORK=192.168.80.0 //*所在网段*// 
    GATEWAY=192.168.80.1

ONBOOT=yes 
    :wq //*保存退出*//

2:复制第一个IP地址配置文件为第二个IP地址配置文件,并修改里面的IP地址:

[root@Linux network-scripts]#cp ifcfg-eth0 ifcfg-eth0:1 //变化的地方 
    [root@Linux network-scripts]#vi ifcfg-eth0:1 //变化的地方,这里与ubuntu系统不同没有ifcfg-eth0:0 
    DEVICE=eth0:1 //变化的地方 
    BOOTPROTO=static 
    BROADCAST=192.168.80.255 //*广播地址*// 
    IPADDR=192.168.80.199 //*第二个IP地址*// 
    NETMASK=255.255.255.0 //*网络掩码*// 
    NETWORK=192.168.80.0 //*所在网段*// 
    ONBOOT=yes 
    :wq //*保存退出*//

注意了,只能有一个网关,将网关地址配置在实际存在的ifcfg-eth0文件里,不要配置到虚拟出来的ifcfg-eth0:1之中。否则有问题。在这里得到一个经验就是配置网关可以直接在ifcfg-eth0或ifcfg-eth1这些配置文件里配置与在network配置文件里配置没有什么不同。

这两种方法的优缺点:第一种方法有个问题就是可能重启之后网卡eth0配置的能起来,eth1可能起不来,同一网段的IP估计应该没问题,都是同一个网关,要是双线,电信和联通双IP配置的话,只能选用方法2比较保险一些,方法1估计有点问题,没有测试过,不过记得有这么两种方法就是了,只能配置电信或是联通的网关作为出口,这样就一定要确保eth0这个真实的网卡配置文件一定要是选作出口的电信或联通的IP配置,而那虚拟的ifcfg-eth1里边配置另一个。

单网卡双IP双网关的配置办法:

单网卡双IP的配置办法如上两种办法,双网关需要执行如下命令:

route add –net 192.168.10.0 netmask 255.255.255.0 gw 192.168.10.1

route add –net 192.168.20.0 netmask 255.255.255.0 gw 192.168.20.1

……..

CentOS 6除了支持以上两种方法之外新版本还支持如下这种配置方法:

在新一版本的centos系统即为centos6这个版本中,有很多地方和之前的版本有所不同,这里也是这样有些差别:

如果要在一个网卡上实现多IP地址,就可以简单的在相应的网卡配置文件中简单的添加如下设置,这里关键,必须的有。

[root@localhost network-scripts]# vi ifcfg-eth1

DEVICE="eth1"

NM_CONTROLLED="yes"

BOOTPROTO=none

ONBOOT="yes"

IPADDR="172.16.1.1"

NETMASK="255.255.0.0"

IPADDR2="172.16.1.2" //这里是新加的IP

IPADDR3="172.16.1.3"

TYPE=Ethernet

PREFIX=16

PREFIX2=16

PREFIX3=16

DEFROUTE=yes

IPV4_FAILURE_FATAL=yes

IPV6INIT=no

NAME="System eth1"

UUID=9c92fad9-6ecb-3e6c-eb4d-8a47c6f50c04

HWADDR=00:0C:29:4E:63:EC //这里也很关键

Ubuntu下配置单网卡双IP:

sudo vi /etc/network/interfaces

# This file describes the network interfaces available on your system

# and how to activate them. For more information, see interfaces(5).

# The loopback network interface

auto lo

iface lo inet loopback

# The primary network interface

auto eth0

iface eth0 inet static

address 119.167.227.17

netmask 255.255.255.192

network 119.167.227.0

broadcast 119.167.227.255

gateway 119.167.227.62

# dns-* options are implemented by the resolvconf package, if installed

dns-nameservers 202.102.128.68

dns-search workgroup

# Virtual IP 01

auto eth0:0

iface eth0:0 inet static

address 119.167.227.18

netmask 255.255.255.192

network 119.167.227.0

broadcast 119.167.227.255

gateway 119.167.227.62

# dns-* options are implemented by the resolvconf package, if installed

dns-nameservers 202.102.128.68

dns-search workgroup

# Virtual IP 02

auto eth0:1

iface eth0:1 inet static

address 119.167.227.19

netmask 255.255.255.192

network 119.167.227.0

broadcast 119.167.227.255

gateway 119.167.227.62

# dns-* options are implemented by the resolvconf package, if installed

dns-nameservers 202.102.128.68

dns-search workgroup

# Virtual IP 03

auto eth0:2

iface eth0:2 inet static

address 119.167.227.20

netmask 255.255.255.192

network 119.167.227.0

broadcast 119.167.227.255

gateway 119.167.227.62

# dns-* options are implemented by the resolvconf package, if installed

dns-nameservers 202.102.128.68

dns-search workgroup

# The second network interface

auto eth1

iface eth1 inet static

address 192.168.1.2

netmask 255.255.255.0

network 192.168.1.0

broadcast 192.168.1.255

阅读(1452) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~