ubuntu server 16.04(amd 64) 配置網橋,多網卡使用激活


 

安裝了Ubuntu16.04的server版本,結果進入系統輸入ifconfig后發現,只有一個網卡enp1s0,還有一個網絡回路lo,ifconfig -a 發現其實一共有四個網卡,enp1s0,enp2s0,enp3s0,enp4s0。

 

我們的工控機有四個網口,現在需要把前三個做成橋接,第四個動態獲取,也就是說前三個網口需要設置成為一個網段,這需要虛擬網橋的幫助。

 

安裝 bridge-utils

sudo apt-get install bridge-utils

創建一個虛擬網橋

sudo brctl addbr br1

其中br1是網橋名,應該可以隨便起.

查看網卡名

sudo ls /proc/sys/net/ipv4/conf

可以看到自己的網卡和剛剛創建的網橋名.
這里假設在某台設備上看到了 enp1s0,enp2s0,enp3s0,enp4s0四個網絡接口,現在為其配置一個網橋.

 

ps:(配置之前,如果網卡正在工作,最好使用sudo ifdown enp1s0將其關掉(enp1s0指正在工作的網卡))

 

配置網橋,打開接口文件

sudo vim /etc/network/interfaces

最好將這個文件先備份一下.

輸入配置代碼

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto enp1s0
iface enp1s0 inet manual
auto enp2s0
iface enp2s0 inet manual
auto enp3s0
iface enp3s0 inet manual 
auto enp4s0
iface enp4s0 inet dhcp 

auto br1
iface br1 inet static
  bridge_ports enp1s0 enp2s0 enp3s0
  gateway 192.168.10.1
  broadcast 192.168.10.255
  netmask 255.255.255.0
  address 192.168.10.2

 

 

以上就是我interfaces文件內的所有內容,我們可以看到前三個網口的網段設置為了10網段,虛擬網橋的IP地址是192.168.10.2,保存修改后,sudo reboot 重啟機器。

開機后,ifconfig,應該能看到網橋,以及四個網卡,還有回路lo.

 

如果想要測試,可以使用一根網線連接到前三個網口中的一個,另一段接入一個路由器,該路由器的網段同樣設置為10網段,然后使用另外一台筆記本,連接到路由器開啟的無線網上,ping 192.168.10.2,如果可以ping 通,證明網橋是可以用的!

 

 

下面的內容是我參考的另一篇博客里面的,區別在於,他的網橋是通過動態IP獲取的,而我們是靜態IP,還有一點就是他把四個網卡全部橋接了,我們只橋接了前三個,第四個是動態獲取。

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto enp1s0
iface enp1s0 inet manual

auto enp2s0
iface enp2s0 inet manual

auto enp3s0
iface enp3s0 inet manual

auto enp4s0
iface enp4s0 inet manual

auto br1
iface br1 inet dhcp
bridge_ports enp1s0
bridge_ports enp2s0
bridge_ports enp3s0
bridge_ports enp4s0
bridge_stp off
bridge_fd 0

 

保存后退出vim,
其中br1網橋采用的是動態ip,即由入網的路由器等設備為br1分配ip.

插上網線,然后使配置生效,輸入

sudo ifdown br1
sudo ifup br1

第一句是關閉網橋,第二句是開啟網橋,如果出現錯誤,需檢查配置是否寫對.

輸入sudo ifconfig 查看結果

 

 

原文參考:

https://blog.csdn.net/And_ZJ/article/details/53856841

https://wenku.baidu.com/view/51fb15742f60ddccdb38a007.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM