centos7.6安装使用

  1. yum install bridge-utils

ubuntu使用

  1. apt-get install bridge-utils

网桥是一种在链路层实现中继,对帧进行转发的技术,根据MAC分区块,可隔离碰撞,将网络的多个网段在数据链路层连接起来的网络设备。

Linux 网桥配置命令:brctl

  1. [root@guanbin-k8s-node sbin]# brctl -help
  2. Usage: brctl [commands]
  3. commands:
  4. addbr <bridge> add bridge
  5. delbr <bridge> delete bridge
  6. addif <bridge> <device> add interface to bridge
  7. delif <bridge> <device> delete interface from bridge
  8. hairpin <bridge> <port> {on|off} turn hairpin on/off
  9. setageing <bridge> <time> set ageing time
  10. setbridgeprio <bridge> <prio> set bridge priority
  11. setfd <bridge> <time> set bridge forward delay
  12. sethello <bridge> <time> set hello time
  13. setmaxage <bridge> <time> set max message age
  14. setpathcost <bridge> <port> <cost> set path cost
  15. setportprio <bridge> <port> <prio> set port priority
  16. show [ <bridge> ] show a list of bridges
  17. showmacs <bridge> show a list of mac addrs
  18. showstp <bridge> show bridge stp info
  19. stp <bridge> {on|off} turn stp on/off

Usage: brctl [commands]

commands:

addbr

<bridge>

add bridge

delbr

<bridge>

delete bridge

addif

<bridge> <device>

add interface to bridge

delif

<bridge> <device>

delete interface from bridge

setageing

<bridge> <time>

set ageing time

setbridgeprio

<bridge> <prio>

set bridge priority

setfd

<bridge> <time>

set bridge forward delay

sethello

<bridge> <time>

set hello time

setmaxage

<bridge> <time>

set max message age

setpathcost

<bridge> <port> <cost>

set path cost

setportprio

<bridge> <port> <prio>

set port priority

show

 

show a list of bridges

showmacs

<bridge>

show a list of mac addrs

showstp

<bridge>

show bridge stp info

stp

<bridge> {on|off}

turn stp on/off

 

  1. [inbi@debian~]#brctl addbr br0

#增加一个网桥

  1. [inbi@debian~]#ifconfig eth0 0.0.0.0 promisc
  2. [inbi@debian~]#ifconfig eth1 0.0.0.0 promisc
  3. [inbi@debian~]#brctl addif br0 eth0 eth1

#将两块已有的网卡添加到网桥,此时这两个网卡工作于混杂模式,所以不需要IP了,因为网桥是工作在链路层的。

  1. [inbi@debian~]#brctl show

#查看已有网桥

你也可以为 br0 设置一个IP,已访问这台机器。

  1. [inbi@debian~]#ifconfig br0 10.10.1.1 netmask 255.255.0.0 up
  1. [inbi@debian~]#brctl delif br0 eth0 eth1

#增加网桥中的接口

  1. [inbi@debian~]#brctl delbr br0

#删除网桥

关闭生成树

  1. [inbi@debian~]#brctl stp br0 off

#关闭生成树协议,减少数据包污染,因为我这里只有一个路由器哦!

配置桥开机激活

  1. [inbi@debian~]#echo "modprobe bridge">>/etc/rc.local

#开机加载 bridge 模块,或者echo “bridge”>>/etc/modules

  1. [inbi@debian~]#cp /etc/network/interfaces /etc/network/interfaces.default

#备份下,方便以后使用啊!

  1. [inbi@debian~]#vim /etc/network/interfaces
  2. auto lo eth0 eth1 br0
  3. iface lo inet loopback
  4. iface br0 inet static
  5. address 10.10.10.1
  6. netmask 255.255.0.0
  7. gateway 10.10.10.254
  8. pre-up ip link set eth0 promisc on
  9. pre-up ip link set eth1 promisc on
  10. pre-up echo "1">/proc/sys/net/ipv4/ip_forward
  11. bridge_ports eth0 eth1

#配置eth0 eth1 br0开机启动,eth0,eth1未设置IP信息,在启动br0网卡时,开启了eth0,eth1的混杂模式,并桥接了它们。

 

  • Linux ifconfig命令用于显示或设置网络设备。
  • ifconfig可设置网络设备的状态,或是显示目前的设置。
  1. yum install net-tools

 ifconfig -help

  1. [root@guanbin-k8s-node sbin]# ifconfig -help
  2. Usage:
  3. ifconfig [-a] [-v] [-s] <interface> [[<AF>] <address>]
  4. [add <address>[/<prefixlen>]]
  5. [del <address>[/<prefixlen>]]
  6. [[-]broadcast [<address>]] [[-]pointopoint [<address>]]
  7. [netmask <address>] [dstaddr <address>] [tunnel <address>]
  8. [outfill <NN>] [keepalive <NN>]
  9. [hw <HW> <address>] [mtu <NN>]
  10. [[-]trailers] [[-]arp] [[-]allmulti]
  11. [multicast] [[-]promisc]
  12. [mem_start <NN>] [io_addr <NN>] [irq <NN>] [media <type>]
  13. [txqueuelen <NN>]
  14. [[-]dynamic]
  15. [up|down] ...
  16. <HW>=Hardware Type.
  17. List of possible hardware types:
  18. loop (Local Loopback) slip (Serial Line IP) cslip (VJ Serial Line IP)
  19. slip6 (6-bit Serial Line IP) cslip6 (VJ 6-bit Serial Line IP) adaptive (Adaptive Serial Line IP)
  20. ash (Ash) ether (Ethernet) ax25 (AMPR AX.25)
  21. netrom (AMPR NET/ROM) rose (AMPR ROSE) tunnel (IPIP Tunnel)
  22. ppp (Point-to-Point Protocol) hdlc ((Cisco)-HDLC) lapb (LAPB)
  23. arcnet (ARCnet) dlci (Frame Relay DLCI) frad (Frame Relay Access Device)
  24. sit (IPv6-in-IPv4) fddi (Fiber Distributed Data Interface) hippi (HIPPI)
  25. irda (IrLAP) ec (Econet) x25 (generic X.25)
  26. infiniband (InfiniBand) eui64 (Generic EUI-64)
  27. <AF>=Address family. Default: inet
  28. List of possible address families:
  29. unix (UNIX Domain) inet (DARPA Internet) inet6 (IPv6)
  30. ax25 (AMPR AX.25) netrom (AMPR NET/ROM) rose (AMPR ROSE)
  31. ipx (Novell IPX) ddp (Appletalk DDP) ec (Econet)
  32. ash (Ash) x25 (CCITT X.25)
  • add<地址> 设置网络设备IPv6的IP地址。
  • del<地址> 删除网络设备IPv6的IP地址。
  • down 关闭指定的网络设备。
  • <hw<网络设备类型><硬件地址> 设置网络设备的类型与硬件地址。
  • io_addr<I/O地址> 设置网络设备的I/O地址。
  • irq<IRQ地址> 设置网络设备的IRQ。
  • media<网络媒介类型> 设置网络设备的媒介类型。
  • mem_start<内存地址> 设置网络设备在主内存所占用的起始地址。
  • metric<数目> 指定在计算数据包的转送次数时,所要加上的数目。
  • mtu<字节> 设置网络设备的MTU。
  • netmask<子网掩码> 设置网络设备的子网掩码。
  • tunnel<地址> 建立IPv4与IPv6之间的隧道通信地址。
  • up 启动指定的网络设备。
  • -broadcast<地址> 将要送往指定地址的数据包当成广播数据包来处理。
  • -pointopoint<地址> 与指定地址的网络设备建立直接连线,此模式具有保密功能。
  • -promisc 关闭或启动指定网络设备的promiscuous模式。
  • [IP地址] 指定网络设备的IP地址。
  • [网络设备] 指定网络设备的名称。

显示网络设备

  1. # ifconfig
  2. eth0 Link encap:Ethernet HWaddr 00:50:56:0A:0B:0C
  3. inet addr:192.168.0.3 Bcast:192.168.0.255 Mask:255.255.255.0
  4. inet6 addr: fe80::250:56ff:fe0a:b0c/64 Scope:Link
  5. UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
  6. RX packets:172220 errors:0 dropped:0 overruns:0 frame:0
  7. TX packets:132379 errors:0 dropped:0 overruns:0 carrier:0
  8. collisions:0 txqueuelen:1000
  9. RX bytes:87101880 (83.0 MiB) TX bytes:41576123 (39.6 MiB)
  10. Interrupt:185 Base address:0x2024
  11. lo Link encap:Local Loopback
  12. inet addr:127.0.0.1 Mask:255.0.0.0
  13. inet6 addr: ::1/128 Scope:Host
  14. UP LOOPBACK RUNNING MTU:16436 Metric:1
  15. RX packets:2022 errors:0 dropped:0 overruns:0 frame:0
  16. TX packets:2022 errors:0 dropped:0 overruns:0 carrier:0
  17. collisions:0 txqueuelen:0
  18. RX bytes:2459063 (2.3 MiB) TX bytes:2459063 (2.3 MiB)

启动关闭指定网卡

  1. # ifconfig eth0 down
  2. # ifconfig eth0 up

为网卡配置和删除IPv6地址

  1. # ifconfig eth0 add 33ffe:3240:800:1005::2/ 64 //为网卡设置IPv6地址
  2. # ifconfig eth0 del 33ffe:3240:800:1005::2/ 64 //为网卡删除IPv6地址

用ifconfig修改MAC地址

  1. # ifconfig eth0 down //关闭网卡
  2. # ifconfig eth0 hw ether 00:AA:BB:CC:DD:EE //修改MAC地址
  3. # ifconfig eth0 up //启动网卡
  4. # ifconfig eth1 hw ether 00:1D:1C:1D:1E //关闭网卡并修改MAC地址
  5. # ifconfig eth1 up //启动网卡

配置IP地址

  1. # ifconfig eth0 192.168.1.56
  2. //给eth0网卡配置IP地址
  3. # ifconfig eth0 192.168.1.56 netmask 255.255.255.0
  4. // 给eth0网卡配置IP地址,并加上子掩码
  5. # ifconfig eth0 192.168.1.56 netmask 255.255.255.0 broadcast 192.168.1.255
  6. // 给eth0网卡配置IP地址,加上子掩码,加上个广播地址

启用和关闭ARP协议

  1. # ifconfig eth0 arp //开启
  2. # ifconfig eth0 -arp //关闭

设置最大传输单元

  1. # ifconfig eth0 mtu 1500
  2. //设置能通过的最大数据包大小为 1500 bytes

 

参考:https://www.runoob.com/linux/linux-comm-ifconfig.html

         https://www.cnblogs.com/lsgxeva/p/8622870.html 

版权声明:本文为guanbin-529原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/guanbin-529/p/13099792.html