码迷,mamicode.com
首页 > 系统相关 > 详细

Linux学习46 Linux网络相关属性配置进阶与实战

时间:2020-03-02 19:10:12      阅读:88      评论:0      收藏:0      [点我收藏+]

标签:inux   ns3   fast   known   packet   out   tns   学习   eth   

一、iproute2家族续

  1、ip命令续

    a、ip link 

    b、ip netns

    c、ip address - protocol address management

      (1)、ip address add :增加一个IP地址 (add new protocol address )

        ip addr add IFADDR dev IFACE 

        1)、现在我们首先用ifconfig命令删除网卡ens37的地址

[root@wohaoshuai1 ~]# ifconfig ens37 
ens37: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.10.61  netmask 255.255.255.0  broadcast 192.168.10.255
        ether 00:0c:29:76:9f:00  txqueuelen 1000  (Ethernet)
        RX packets 65  bytes 5556 (5.4 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 199  bytes 34302 (33.4 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@wohaoshuai1 ~]# ifconfig ens37 0
[root@wohaoshuai1 ~]# ifconfig ens37 
ens37: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether 00:0c:29:76:9f:00  txqueuelen 1000  (Ethernet)
        RX packets 107  bytes 9524 (9.3 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 217  bytes 36566 (35.7 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

        2)、然后我们给网卡ens37配置IP地址

[root@wohaoshuai1 ~]# ifconfig ens37 
ens37: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether 00:0c:29:76:9f:00  txqueuelen 1000  (Ethernet)
        RX packets 107  bytes 9524 (9.3 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 217  bytes 36566 (35.7 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
[root@wohaoshuai1 ~]# ip addr add 192.168.10.61/24 dev ens37
[root@wohaoshuai1 ~]# ifconfig ens37 
ens37: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.10.61  netmask 255.255.255.0  broadcast 0.0.0.0
        ether 00:0c:29:76:9f:00  txqueuelen 1000  (Ethernet)
        RX packets 117  bytes 10308 (10.0 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 224  bytes 37520 (36.6 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

          其实我们可以再给ens37添加一个地址

[root@wohaoshuai1 ~]# ip addr add 192.168.10.62/24 dev ens37
[root@wohaoshuai1 ~]# ip add show ens37
3: ens37: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:76:9f:00 brd ff:ff:ff:ff:ff:ff
    inet 192.168.10.61/24 scope global ens37
       valid_lft forever preferred_lft forever
    inet 192.168.10.62/24 scope global secondary ens37
       valid_lft forever preferred_lft forever

          然后我们还可以再给ens37再添加一个地址

[root@wohaoshuai1 ~]# ip addr add 10.0.10.100/8 dev ens37
[root@wohaoshuai1 ~]# ip add show ens37
3: ens37: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:76:9f:00 brd ff:ff:ff:ff:ff:ff
    inet 192.168.10.61/24 scope global ens37
       valid_lft forever preferred_lft forever
    inet 10.0.10.100/8 scope global ens37
       valid_lft forever preferred_lft forever
    inet 192.168.10.62/24 scope global secondary ens37
       valid_lft forever preferred_lft forever

          我们可以看到现在ens37网卡上有两个地址,其中192.168.10.61和10.0.10.100俩个是global地址,另一个192.168.10.62是secondary(第二的)地址。为什么其它两个地址中有一个是global地址有一个是secondary地址呢?因为在同一个网段中我们的地址才分第一地址和第二地址。

 

 

      (2)、ip address delete :删除一个IP地址(delete protocol address)

      (3)、ip address show :查看一个IP地址(look at protocol addresses)

[root@wohaoshuai1 ~]# ip add show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:76:9f:f6 brd ff:ff:ff:ff:ff:ff
    inet 192.168.10.41/24 brd 192.168.10.255 scope global noprefixroute ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::2af8:1ecb:eb2c:861f/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
3: ens37: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:76:9f:00 brd ff:ff:ff:ff:ff:ff
    inet6 fe80::ab38:1308:dcd7:37ec/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever

        也可以写作 ip add list

      (4)、ip address flush:清空接口所有的IP地址,假如一个接口配了多个IP那么所有的IP都会被删除掉

 

Linux学习46 Linux网络相关属性配置进阶与实战

标签:inux   ns3   fast   known   packet   out   tns   学习   eth   

原文地址:https://www.cnblogs.com/Presley-lpc/p/12397280.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!