linux 系統單網絡卡繫結多個IP位址方法

2021-06-26 10:16:50 字數 2071 閱讀 2177

如果linux 系統只有乙個物理網絡卡,而在實際使用中,有時需要配置單網絡卡具備多個ip 位址。

步驟:1、root登入 linux系統

2、檢視現有網路配置

[root@localhost ~]# cd /etc/sysconfig/network-scripts/

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

device=eth0

onboot=yes

bootproto=static

ipaddr=192.168.50.222

netmask=255.255.255.0

gateway=192.168.50.1

3、配置新的虛擬網絡卡

注:仍然保留原有ifcfg-eth0檔案,所以採用複製方式。

[root@localhost network-scripts]# cp ifcfg-eth0ifcfg-eth0:1

[root@localhost network-scripts]# viifcfg-eth0:1 

device=eth0:1

onboot=yes

bootproto=static

ipaddr=10.1.1.100

netmask=255.255.255.0

gateway=10.1.1.1

[root@localhost network-scripts]# service network restart

4、檢視目前路由

route -n

destination 

gateway 

genmask 

flags metricref 

useiface

192.168.50.0 

0.0.0.0 

255.255.255.0 

u 0 

0 0 eth0

10.1.1.0 

0.0.0.0 

255.255.255.0 

u 0 

0 0 eth0

0.0.0.0 

192.168.50.1  

0.0.0.0 

ug 0 

0 0 eth0

如果只需要預設路由,則這樣設定就可以啦。

route add -net 192.168.50.0/24 gw 192.168.50.1 dev eth0

route add -net 10.1.1.0/24 gw 10.1.1.1  deveth0:1

這樣,源位址192.168.50.x網段預設走 eth0;源位址10.1.1.x的網段預設走eth0:1

其它的ip預設走eth0

檢視路由資訊如下:

route -n

destination 

gateway 

genmask 

flags metricref 

useiface

192.168.50.0 

0.0.0.0 

255.255.255.0 

u 0 

0 0 eth0

192.168.50.0 

192.168.50.1 

255.255.255.0 

ug 0 

0 0 eth0

10.1.1.0 

10.1.1.1 

255.255.255.0 

ug 0 

0 0 eth0

10.1.1.0 

0.0.0.0 

255.255.255.0 

u 0 

0 0 eth0

169.254.0.0 

0.0.0.0 

255.255.0.0 

u 0 

0 0 eth0

0.0.0.0 

192.168.50.1 

0.0.0.0 

ug 0 

0 0 eth0

用route -n 命令增加的路由在網路重啟後,則路由丟失,可通過增加到rc.local 等多種方式實現永久保持。

《完》原文:

linux 單網絡卡繫結多個IP

linux 單網絡卡繫結多個ip 配置預設閘道器 預設閘道器的檔案 etc sysconfig network 內容如下 其中test為主機名稱 networking yes hostname test gateway 192.168.168.250 或 nozeroconf yes gateway...

Ubuntu 單網絡卡繫結多個IP

注 我的是eth0,但別的電腦可能不同,具體檢視命令ifconfig,將你電腦出現的ethx替換成下文的eth0 第一種方法 快遞建立 刪除虛擬網絡卡 sudo ifconfig eth0 0 192.168.10.10 up 以上的命令就可以在eth0網絡卡上建立乙個叫eth0 0的虛擬網絡卡,他...

linux系統單網絡卡繫結雙IP的方法

linux系統單網絡卡繫結雙ip的方法 1.進入目錄 cd etc sysconfig network scripts advanced micro devices amd 79c970 pcnet32 lance device eth0 bootproto static broadcast 192...