Linux一塊網絡卡配置多個IP

2021-06-11 20:14:34 字數 2050 閱讀 8374

不同的linux distribution一塊網絡卡配置多個ip的方法基本相同,只不過編輯的檔案不同。

1. ubuntu 配置多個ip

原來的inte***ces為:

auto eth0

iface eth0 inet static

name ethernet lan card

address 192.168.1.2

netmask 255.255.255.0

network 192.168.1.0

broadcast 192.168.1.255

gateway 192.168.1.1

auto eth0

iface eth0 inet static

name ethernet lan card

address 192.168.1.2

netmask 255.255.255.0

network 192.168.1.0

broadcast 192.168.1.255

gateway 192.168.1.1

auto eth0:0

iface eth0:0 inet static

name ethernet

address 192.168.2.2

netmask 255.255.255.0

network 192.168.2.0

broadcast 192.168.2.255

gateway 192.168.2.1

2. 國產linux(red hat ,centos等)

device=eth0

bootproto=static

broadcast=192.168.4.255

hwaddr=xx:xx:xx:xx:xx:xx

ipaddr=192.168.4.2

netmask=255.255.255.0

network=192.168.4.0

onboot=yes

type=ethernet

gateway=192.168.4.1

dns1=192.168.0.20

dns2=192.168.0.21

device=eth0

bootproto=static

broadcast=192.168.4.255

hwaddr=xx:xx:xx:xx:xx:xx

ipaddr=192.168.4.2

netmask=255.255.255.0

network=192.168.4.0

onboot=yes

type=ethernet

gateway=192.168.4.1

dns1=192.168.0.20

dns2=192.168.0.21

device=eth0:0

bootproto=static

broadcast=192.168.1.255

hwaddr=xx:xx:xx:xx:xx:xx

ipaddr=192.168.1.2

netmask=255.255.255.0

network=192.168.1.0

onboot=yes

type=ethernet

gateway=192.168.1.1

dns1=192.168.0.20

dns2=192.168.0.21

【注】:1.國產linux中要是配置後的多個ip生效,每次啟動系統之後都必須重啟網路,而且需要將能上網的ip編輯到最後,上面的例子中就應該寫到eth0:0裡,ubuntu沒出現類似問題。

2.如果安裝的是桌面版的linux,則設定上述的配置檔案會和桌面環境下配置的ip衝突,而且桌面環境下無法給一塊網絡卡配置多個ip,即使配置了也只有最前面的生效,因此我們建議使用配置檔案的方式實現一塊網絡卡多個ip的配置,而且為了防止衝突需要在配置前將linux的執行模式轉換為mode 3,即執行#init 3,然後重啟網路,通過配置檔案配置的ip就會生效。但是轉換linux執行模式會將gnome 或kde程序殺掉,所以桌面環境就不能使用了,所以還是建議安裝伺服器版linux。

一塊網絡卡設定多個IP位址

linux下 兩種方法 第一種ifconfig eth0 192.168.1.1 ifconfig eth0 1 192.168.2.1 ifconfig eth0 2 192.168.3.1 第二種 ip addr add 192.168.1.1 ip addr add 192.168.2.1 i...

Linux 在一塊網絡卡上繫結多個IP

配置虛擬主機時有一種方式是在一塊網絡卡上繫結多個ip,操作如下 首先用ifconfig檢視物理網絡卡 code shell ifconfig eth0 link encap ethernet hwaddr 08 00 27 98 1c 2e inet addr 192.168.1.103 bcast...

ubuntu下一塊網絡卡繫結多個ip

常常我們有需要乙個網絡卡象windows一樣設定多個ip。下面我們看看在ubuntu下怎麼樣做.我們先開啟網路介面的檔案 sudo vi etc network inte ces 只需 eth0 新增eth0 0 auto eth0 iface eth0 inet static address 19...