日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 运维知识 > linux >内容正文

linux

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

發(fā)布時(shí)間:2023/12/10 linux 49 豆豆
生活随笔 收集整理的這篇文章主要介紹了 linux 单网卡 双ip,Linux操作系统单网卡双IP的设置 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

Centos5下:

1、配置第一個(gè)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 //*第一個(gè)IP地址*//

NETMASK=255.255.255.0 //*網(wǎng)絡(luò)掩碼*//

NETWORK=192.168.80.0 //*所在網(wǎng)段*//

ONBOOT=yes

:wq //*保存退出*//

2、復(fù)制第一個(gè)IP地址配置文件為第二個(gè)IP地址配置文件,并修改里面的IP地址:

[root@Linux network-scripts]#cp ifcfg-eth0 ifcfg-eth1

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

DEVICE=eth0:1 //用eth0也可以,也能通,但是重啟網(wǎng)卡時(shí)會(huì)提示eth0 file existed!

BOOTPROTO=static

BROADCAST=192.168.80.255 //*廣播地址*//

IPADDR=192.168.80.199 //*第二個(gè)IP地址*//

NETMASK=255.255.255.0 //*網(wǎng)絡(luò)掩碼*//

NETWORK=192.168.80.0 //*所在網(wǎng)段*//

ONBOOT=yes

:wq //*保存退出*//

3、重啟網(wǎng)卡:

[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

方法二:在配置第二個(gè)IP地址的時(shí)候有變化其他

1、配置第一個(gè)IP地址以及網(wǎng)關(guān):

[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 //*第一個(gè)IP地址*//

NETMASK=255.255.255.0 //*網(wǎng)絡(luò)掩碼*//

NETWORK=192.168.80.0 //*所在網(wǎng)段*//

GATEWAY=192.168.80.1

ONBOOT=yes

:wq //*保存退出*//

2:復(fù)制第一個(gè)IP地址配置文件為第二個(gè)IP地址配置文件,并修改里面的IP地址:

[root@Linux network-scripts]#cp ifcfg-eth0 ifcfg-eth0:1 //變化的地方

[root@Linux network-scripts]#vi ifcfg-eth0:1 //變化的地方,這里與ubuntu系統(tǒng)不同沒有ifcfg-eth0:0

DEVICE=eth0:1 //變化的地方

BOOTPROTO=static

BROADCAST=192.168.80.255 //*廣播地址*//

IPADDR=192.168.80.199 //*第二個(gè)IP地址*//

NETMASK=255.255.255.0 //*網(wǎng)絡(luò)掩碼*//

NETWORK=192.168.80.0 //*所在網(wǎng)段*//

ONBOOT=yes

:wq //*保存退出*//

注意了,只能有一個(gè)網(wǎng)關(guān),將網(wǎng)關(guān)地址配置在實(shí)際存在的ifcfg-eth0文件里,不要配置到虛擬出來的ifcfg-eth0:1之中。否則有問題。在這里得到一個(gè)經(jīng)驗(yàn)就是配置網(wǎng)關(guān)可以直接在ifcfg-eth0或ifcfg-eth1這些配置文件里配置與在network配置文件里配置沒有什么不同。

這兩種方法的優(yōu)缺點(diǎn):第一種方法有個(gè)問題就是可能重啟之后網(wǎng)卡eth0配置的能起來,eth1可能起不來,同一網(wǎng)段的IP估計(jì)應(yīng)該沒問題,都是同一個(gè)網(wǎng)關(guān),要是雙線,電信和聯(lián)通雙IP配置的話,只能選用方法2比較保險(xiǎn)一些,方法1估計(jì)有點(diǎn)問題,沒有測(cè)試過,不過記得有這么兩種方法就是了,只能配置電信或是聯(lián)通的網(wǎng)關(guān)作為出口,這樣就一定要確保eth0這個(gè)真實(shí)的網(wǎng)卡配置文件一定要是選作出口的電信或聯(lián)通的IP配置,而那虛擬的ifcfg-eth1里邊配置另一個(gè)。

單網(wǎng)卡雙IP雙網(wǎng)關(guān)的配置辦法:

單網(wǎng)卡雙IP的配置辦法如上兩種辦法,雙網(wǎng)關(guān)需要執(zhí)行如下命令:

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系統(tǒng)即為centos6這個(gè)版本中,有很多地方和之前的版本有所不同,這里也是這樣有些差別:

如果要在一個(gè)網(wǎng)卡上實(shí)現(xiàn)多IP地址,就可以簡(jiǎn)單的在相應(yīng)的網(wǎng)卡配置文件中簡(jiǎn)單的添加如下設(shè)置,這里關(guān)鍵,必須的有。

[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 //這里也很關(guān)鍵

Ubuntu下配置單網(wǎng)卡雙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

以上是自己工作中的一個(gè)配置例子。親測(cè)。

總結(jié)

以上是生活随笔為你收集整理的linux 单网卡 双ip,Linux操作系统单网卡双IP的设置的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。