系统网卡增加地址及配置路由

mac

添加地址

sudo ifconfig en4 alias 129.9.$i.111 netmask 255.255.255.0

添加路由

add net 72.52.94.234: gateway 10.8.0.1

linux

centos

vconfig 命令

vconfig add eth0 101<br>
vconfig set_flag eth0.101 1 1<br> ## 设置VLAN的REORDER_HDR参数,默认就行<br>
ifconfig eth0.101 192.168.2.2 netmask 255.255.255.0 up<br> ##增加eth0.101子接口的IP地址(注意要地址唯一,本地与对端同一个地址段)<br>
ip addr flush eth0<br> ##清除eth0上的IP地址<br>
vconfig rem eth0.101<br> ##删除eth0上的vlan 101

ip 命令

 ip link add link eth0 name eth0.8 type vlan id 8
 ip link set eth0.8 up  
ip addr add 192.168.1.10/24 dev eth0.8 
ip addr add 192.168.1.10/24 dev eth0.8 label eth0:8 # label 后面 eth0:8 为ip地址对应的别名
 
To view the VLAN, issue the following command:
~]$ ip -d link show eth0.8
4: eth0.8@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT
     link/ether 52:54:00:ce:5f:6c brd ff:ff:ff:ff:ff:ff promiscuity 0
     vlan protocol 802.1Q id 8 <REORDER_HDR>

~]# ip link delete eth0.8

配置文件

配置文件:
总结:修改父接口的BOOTPROTO=manual
复制父接口,
清空内容
注入下面的内容:
[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-p1p1.1610
PHYSDEV=p1p1
VLAN=yes
TYPE=Vlan
VLAN_ID=1610
REORDER_HDR=yes
GVRP=no
MVRP=no
BOOTPROTO=none
IPADDR=10.20.10.44
PREFIX=29
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
NAME=p1p1.1610
ONBOOT=yes

或者
cat /etc/sysconfig/network-scripts/ifcfg-p1p1.1610
DEVICE=ens224.379
BOOTPROTO=none
ONBOOT=yes
MACADDR=18:bd:76:43:71:4e
VLAN=yes

其他

linux 查看arp 表

ip nei 

linux 删除arp 记录

ip neigh flush  dev eth0  
ip neigh flush 192.168.1.10



# centos 配置lacp 聚合口+vlan 案例
  1. 关闭NetworkManager服务
    systemctl stop NetworkManager;systemctl disable NetworkManager
  2. 配置文件参考
    DEVICE=bond0
    Type=Bond
    NAME=bond0
    BONDING_MASTER=yes
    BOOTPROTO=none
    ONBOOT=yes
    NM_CONTROLLED=no
    BONDING_OPTS="mode=4 miimon=100 lacp_rate=1"

[root@server_1 network-scripts]# cat ifcfg-bond0.1001
DEVICE=bond0.1001
BOOTPROTO=none
ONBOOT=yes
VLAN=yes
IPADDR=103.26.0.1
NETMASK=255.255.255.192
GATEWAY=103.26.0.62
DNS1=114.114.114.114

[root@server_1 network-scripts]# cat ifcfg-p5p2
DEVICE=p4p2
TYPE=Ethernet
BOOTPROTO=none
ONBOOT=yes
NM_CONTROLLED=no
IPV6INIT=no
MASTER=bond0
SLAVE=yes

  1. 重启网络服务
    systemctl restart network

netplan 聚合

root@X86-9FFC3D08DC255217:~# cat /etc/netplan/00-installer-config.yaml
# This is the network config written by 'subiquity'
network:
  version: 2
  renderer: networkd
  ethernets:
    eno5:
      dhcp4: no
      dhcp6: no
    eno6:
      dhcp4: no
      dhcp6: no

  bonds:
    bond0:
      interfaces:
        - eno5
        - eno6
      parameters:
        mode: 802.3ad
        lacp-rate: fast
        mii-monitor-interval: 100
        transmit-hash-policy: layer3+4
      addresses:
        - 103.212.56.122/25   # IPv4 地址
          #- 103.212.56.118/25   # IPv4 地址
        - 2404:ff80:100:1::3/120   # IPv6 地址
      routes:
          - to: default
            via: 103.212.56.30
          - to: default
            via: 2404:ff80:100:1::1
      nameservers:
          addresses:
            - 8.8.8.8
posted @ 2022-03-13 21:05  lifei888  阅读(153)  评论(0)    收藏  举报