zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    C语言文件操作函数大全
    iOS
    HDU 5042 GCD pair 预处理+二分 分段
    swoole新手教程01-环境搭建及扩展安装
    Cocos2d-X中的Slider控件
    CSS之BFC
    代理server的概要知识
    C#比較对象的相等性
    Effective C++ 35,36,37
    oled屏幕
  • 原文地址:https://www.cnblogs.com/sea-stream/p/9836968.html
Copyright © 2011-2022 走看看