网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

CentOs网络管理:ifconfig家族,iproute家族及配置文件

 CentOs网络管理:ifconfig家族,iproute家族及配置文件

成都创新互联从2013年成立,先为临淄等服务建站,临淄等地企业,进行企业商务咨询服务。为临淄企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。


在centos的网络管理中ifcfg家族一直占有举足轻重的位置,这个家族陪伴着centos走过了艰苦创业的青春岁月。但是按照社会法则,逐渐壮大的centos正在逐渐冷落这个糟糠之妻,迎娶对自己前途更有帮助的更庞大的家族--iproute家族。ifcfg家族正在滑向冷宫,iproute家族即将入住正宫。


ifcfg命令家族

 

ifconfig命令:用于接口及地址查看和管理

ifconfig 显示一启用的网卡信息

[root@yph7 ~]# ifconfig----------显示已启用的网络接口的状态信息
eno16777736: flags=4163  mtu 1500
        inet 172.16.59.1  netmask 255.255.0.0  broadcast 172.16.255.255
        inet6fe80::20c:29ff:fe90:fa11  prefixlen64  scopeid 0x20
        ether00:0c:29:90:fa:11  txqueuelen 1000  (Ethernet)
        RX packets 641674  bytes 40563451 (38.6 MiB)
        RX errors 0  dropped 169 overruns 0  frame 0
        TX packets 18804  bytes 10014415 (9.5 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0 collisions 0
 
lo: flags=73 mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128 scopeid 0x10
        loop  txqueuelen 0 (Local Loopback)
        RX packets 131  bytes 7618 (7.4 KiB)
        RX errors 0  dropped 0 overruns 0  frame 0
        TX packets 131  bytes 7618 (7.4 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0 collisions 0


ifconfig -a:显示所有接口,包括inactive状态的接口;

[root@yph7 ~]# ifconfig –a   -------发现多了一块网卡,这块网卡未被启用
eno16777736:flags=4163  mtu 1500
        inet172.16.59.1  netmask 255.255.0.0  broadcast 172.16.255.255
        inet6fe80::20c:29ff:fe90:fa11  prefixlen64  scopeid 0x20
        ether00:0c:29:90:fa:11  txqueuelen 1000  (Ethernet)
        RXpackets 646011  bytes 40828485 (38.9 MiB)
        RXerrors 0  dropped 169  overruns 0 frame 0
        TXpackets 18835  bytes 10018077 (9.5 MiB)
        TXerrors 0  dropped 0 overruns 0  carrier 0 collisions 0
 
eno33554984:flags=4098 mtu 1500 -
        ether00:0c:29:90:fa:1b  txqueuelen 1000  (Ethernet)
        RXpackets 0  bytes 0 (0.0 B)
        RXerrors 0  dropped 0  overruns 0 frame 0
        TXpackets 0  bytes 0 (0.0 B)
        TXerrors 0  dropped 0 overruns 0  carrier 0 collisions 0
 
lo: flags=73  mtu 65536
        inet127.0.0.1  netmask 255.0.0.0
        inet6::1  prefixlen 128  scopeid 0x10
       loop  txqueuelen 0  (Local Loopback)
        RXpackets 131  bytes 7618 (7.4 KiB)
        RXerrors 0  dropped 0  overruns 0 frame 0
        TXpackets 131  bytes 7618 (7.4 KiB)
        TXerrors 0  dropped 0 overruns 0  carrier 0 collisions 0

查看指定网络接口的状态信息:

[root@yph7 ~]# ifconfigeno33554984
eno33554984:flags=4098 mtu 1500
        ether 00:0c:29:90:fa:1b  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0 overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0 collisions 0

配置IP地址、掩码

ifconfig  IFACE IP/MASK  [up|down]

为指定网络接口配置ip和子网掩码,并能够启用或停用此网络接口

----设置ip和netmask,并启用该网卡,下图出现“up”说明该网卡已启用

 CentOs网络管理:ifconfig家族,iproute家族及配置文件

另外一种设置子网掩码的方式

ifconfig  IFACE IP  netmask  NETMASK

[root@yph7 ~]# ifconfig eno33554984 192.168.254.254netmask 255.255.255.0
[root@yph7 ~]# ifconfig eno33554984
eno33554984: flags=4099  mtu 1500
        inet192.168.254.254  netmask255.255.255.0  broadcast 192.168.254.255
        ether00:0c:29:90:fa:1b  txqueuelen 1000  (Ethernet)
        RXpackets 0  bytes 0 (0.0 B)
        RXerrors 0  dropped 0  overruns 0 frame 0
        TXpackets 0  bytes 0 (0.0 B)
        TXerrors 0  dropped 0 overruns 0  carrier 0 collisions 0

停用此网卡,“up”消失,说明此网卡已经停用

 CentOs网络管理:ifconfig家族,iproute家族及配置文件

删除IP地址

[root@yph7 apache2]# ifconfig eth0 0  删除eth0的ip地址
[root@yph7 apache2]# ifconfig eth0    查看eth0的信息
eth0      Link encap:Ethernet  HWaddr 00:0C:29:40:7C:9B  
          inet6 addr: fe80::20c:29ff:fe40:7c9b/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:3518 errors:0 dropped:0 overruns:0 frame:0
          TX packets:208 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:331302 (323.5 KiB)  TX bytes:56048 (54.7 KiB)


ifconfig  [-]promisc混杂模式启用或关闭

开启混杂模式

 CentOs网络管理:ifconfig家族,iproute家族及配置文件

关闭混杂模式,“PROMISC”消失

 CentOs网络管理:ifconfig家族,iproute家族及配置文件

注意:ifconfig命令会立即送往内核中的TCP/IP协议栈,并生效;

 

 

route命令:路由查看及管理

 

路由条目类型:

主机路由:目标地址为单个IP;

网络路由:目标地址为IP网络;

默认路由:目标为任意网络,0.0.0.0/0.0.0.0

 

查看:显示查看路由条目

route  -n以数字格式显示路由信息,而不要反解,因为反解会消耗系统资源的

[root@yph7 ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         172.16.0.1      0.0.0.0         UG    100    0        0 eno16777736
172.16.0.0      0.0.0.0         255.255.0.0     U     100    0        0 eno16777736
192.168.0.0     0.0.0.0         255.255.255.0   U     0      0        0 eno33554984

Destination指目标网络的地址,Genmask指目标网络的掩码。

Gateway指下一跳网关地址,Gateway为0.0.0.0说明不需要网关,直连路由。

Metric指到达这个地址需要的开销

Flags:路由条目的状态,U表示启用。G表示网关,但不一定是默认网关。

Iface:自己本地的网卡接口

 

 

添加一个路由,格式:

route  add  [-net|-host]  target [netmask  NETMASK]  [gw GW] [[dev] If]

添加一个路由:以10.0.0.0/8为目的,以192.168.0.1为下一跳,通过eno33554984接口

由于10.0.0.0为网络地址,所以用-net。

下一跳地址必须是自己Destination能到的,由于我有两个网卡,其中一块网卡的IP为192.168.0.5,所以其Destination为192.168.0.0,所以如果要通过这块网卡添加路由的时候,gw就必须是192.168.0.x;通过另一块网卡添加是也是同一道理。

[root@yph7 ~]# route add -net 10.0.0.0/8 gw 192.168.0.1 eno33554984
[root@yph7 ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         172.16.0.1      0.0.0.0         UG    100    0        0 eno16777736
10.0.0.0        192.168.0.1     255.0.0.0       UG    0      0        0 eno33554984
172.16.0.0      0.0.0.0         255.255.0.0     U     100    0        0 eno16777736
192.168.0.0     0.0.0.0         255.255.255.0   U     0      0        0 eno33554984

添加默认网关,下面这两种添加方式结果是一样的,default相当于-net 0.0.0.0/0.0.0.0

[root@yph7 ~]# route add default gw 192.168.0.2 
[root@yph7 ~]# route add -net 0.0.0.0 netmask 0.0.0.0 gw 192.168.0.2
[root@yph7 ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.0.2     0.0.0.0         UG    0      0        0 eno33554984
0.0.0.0         172.16.0.1      0.0.0.0         UG    100    0        0 eno16777736
10.0.0.0        192.168.0.1     255.0.0.0       UG    0      0        0 eno33554984
172.16.0.0      0.0.0.0         255.255.0.0     U     100    0        0 eno16777736
192.168.0.0     0.0.0.0         255.255.255.0   U     0      0        0 eno33554984

 

删除路由

route  del [-net|-host] target  [gw Gw]  [netmask Nm] [[dev] If]

删除默认网关:

[root@yph7 ~]# route del default
[root@yph7 ~]# route -n
Kernel IP routing table  ----------以192.168.0.2为gw的默认网关已经没了
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         172.16.0.1      0.0.0.0         UG    100    0        0 eno16777736
10.0.0.0        192.168.0.1     255.0.0.0       UG    0      0        0 eno33554984
172.16.0.0      0.0.0.0         255.255.0.0     U     100    0        0 eno16777736
192.168.0.0     0.0.0.0         255.255.255.0   U     0      0        0 eno33554984

删除如果有重复的Destination的话,就必须指定gw

[root@yph7 ~]# route del -net 10.0.0.0/8 gw 192.168.0.1
[root@yph7 ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         172.16.0.1      0.0.0.0         UG    100    0        0 eno16777736
172.16.0.0      0.0.0.0         255.255.0.0     U     100    0        0 eno16777736
192.168.0.0     0.0.0.0         255.255.255.0   U     0      0        0 eno33554984

 

netstat命令:

Print networkconnections, routing tables, interface statistics, masquerade connections, andmulticast  memberships,显示网络连接状态,接口状态,路由表等信息。

 

netstat  -rn显示路由表,与route –n相似

-r:routing,显示内核路由表

-n:数字格式

[root@yph7 ~]#netstat -rn
Kernel IP routingtable
Destination     Gateway         Genmask        Flags  MSS Window  irtt Iface
0.0.0.0         172.16.0.1      0.0.0.0         UG        0 0          0 eno16777736
172.16.0.0      0.0.0.0         255.255.0.0     U        0 0          0 eno16777736

 

显示网络连接:

-t:显示已经建立的TCP协议的相关连接,连接均有其状态;FSM(Finate State Machine)有限状态机包含的状态;

[root@yph7 ~]# netstat -t
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0     52 localhost:ssh           localhost:49973         ESTABLISHED

如果加上-n就不会反解主机名,直接以数字显示

[root@yph7 ~]# netstat -tn
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0     52 172.16.59.1:22          172.16.59.0:49973       ESTABLISHED

proto:协议

recv-Q:接收队列,等待接收的队列长度

send-Q:发送队列,等待发送的长度

LocalAddress:本地主机地址

Foreign Address:远程连接地址

State:所处的状态

-u:UDP已经进行的相关的连接,没有状态概念了

[root@yph7 ~]# netstat -un  -------由于有udp相关服务,所以没法显示
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
[root@yph7 ~]#

-w:raw socket裸套接字相关的连接

-l:处于监听状态的连接,一直处于等待接待别人的状态。

-a:所有状态

-n:以数字格式显示IP和Port;

-e:扩展格式;user为0说明是root启动此进程,Inode表示对应的套接字文件的inode号

[root@yph7 ~]# netstat -tne
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address   Foreign Address      State       User       Inode     
tcp        0      0 172.16.59.1:22  172.16.59.0:49973    ESTABLISHED 0          20867


-p:显示相关的进程及PID;

常用组合:

-tnl:加上l说明处于监听状态,一直在全神贯注的关注着网络信息,State变成了“LISTEN”

[root@yph7 ~]# netstat -tnl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN     
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN     
tcp6       0      0 :::22                   :::*                    LISTEN     
tcp6       0      0 ::1:25                  :::*                    LISTEN

-unl:监听udp,因为udp没有状态一说,所以State一栏就没有内容

[root@yph7 ~]# netstat -unl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
udp        0      0 0.0.0.0:123             0.0.0.0:*                          
udp        0      0 127.0.0.1:323           0.0.0.0:*                          
udp6       0      0 :::123                  :::*                               
udp6       0      0 ::1:323                 :::*

-tunlp:同时监听tcp和udp,PID指的是哪个进程在监听。

[root@yph7 ~]# netstat -tnulp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address      State       PID/Program name    
tcp        0      0 0.0.0.0:22              0.0.0.0:*            LISTEN      1037/sshd   tcp        0      0 127.0.0.1:25            0.0.0.0:*            LISTEN      2163/master tcp6       0      0 :::22                   :::*                 LISTEN      1037/sshd   tcp6       0      0 ::1:25                  :::*                 LISTEN      2163/master udp        0      0 0.0.0.0:123             0.0.0.0:*                        807/chronyd udp        0      0 127.0.0.1:323           0.0.0.0:*                        807/chronyd udp6       0      0 :::123                  :::*                             807/chronyd udp6       0      0 ::1:323                 :::*                             807/chronyd


 -tan: 显示tcp状态机里所有状态链接。如下,既显示通信状态的链接,又显示监听等状态

[root@yph7 ~]# netstat -tan
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN     
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN     
tcp        0     52 172.16.59.1:22          172.16.59.0:49973       ESTABLISHED
tcp6       0      0 :::22                   :::*                    LISTEN     
tcp6       0      0 ::1:25                  :::*                    LISTEN

-uan:如下,由于udp暂时没有通信,所以只显示了监听状态的链接 

[root@yph7 ~]# netstat -uan
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
udp        0      0 0.0.0.0:123             0.0.0.0:*                          
udp        0      0 127.0.0.1:323           0.0.0.0:*                          
udp6       0      0 :::123                  :::*                               
udp6       0      0 ::1:323                 :::*


传输层协议:

tcp:面向连接的协议;通信开始之前,要建立一个虚链路;通信完成后还要拆除连接;类似打电话,双方都要准备,双方都要被占线,结束后要解除联系,否则别人就打不进来。

udp:无连接的协议;直接发送数据报文;类似写信,发过去不需让对方确认,不会占线。

 

显示接口的统计数据:

netstat    {--interfaces|-I|-i}    [iface]  [--all|-a]   [--extend|-e]   [--verbose|-v]   [--program|-p]  [--numeric|-n]

 

 -i:显示所有接口的相关统计信息

[root@yph7 ~]# netstat -i
Kernel Interface table
Iface      MTU    RX-OK RX-ERR RX-DRP RX-OVR    TX-OK TX-ERR TX-DRP TX-OVR Flg
eno16777  1500     9504      0     17 0          1104      0      0      0 BMRU
eno33554  1500        0      0      0 0             0      0      0      0 BMU
lo       65536        6      0      0 0             6      0      0      0 LRU

 -I:显示指定指定接口的相关统计信息,注意:“-I”和接口名之间没有空格

[root@yph7 ~]# netstat -Ieno33554984
Kernel Interface table
Iface      MTU    RX-OK RX-ERR RX-DRP RX-OVR    TX-OK TX-ERR TX-DRP TX-OVR Flg
eno33554  1500        0      0      0 0             0      0      0      0 BMU

ifup/ifdown命令:启用或禁某网卡

注意:通过配置文件/etc/sysconfig/network-scripts/ifcfg-IFACE来识别接口并完成配置;如果新添加的网卡没有配置文件,必须手动添加后再使用此命令。例如我要手动添加/etc/sysconfig/network-scripts/ifcfg-eno33554984这个配置文件后才可以使用这两个命令。

 

 

hostname查看和配置主机名:

查看主机名:

[root@yph7 ~]# hostname
yph7.localdomain

配置主机名:但只对当前系统有效,重启后无效;而且是在设置好主机名后,系统重启前这个范围登陆的用户生效。也就是是说设置好主机名后,退出登陆再登陆才生效,所以下面的例子并没有看到生效。

[root@yph7 ~]# hostname vbird
[root@yph7 ~]# hostname
vbird

hostnamectl命令:只适用于CentOS 7。 查看帮助用hostnamectl --help

hostnamectl  status:显示当前主机名的详细信息;

[root@yph7 ~]# hostnamectl status
   Static hostname: yph7.localdomain
Transient hostname: yph7
         Icon name: computer-vm
           Chassis: vm
        Machine ID: 0ceb40c75866411c8ccc966de90ff915
           Boot ID: 0d23420528e0406480bb2ba9d87aaaec
    Virtualization: vmware
  Operating System: CentOS Linux 7 (Core)
       CPE OS Name: cpe:/o:centos:centos:7
            Kernel: Linux 3.10.0-229.el7.x86_64
      Architecture: x86_64

hostnamectl  set-hostname  NAME:设定主机名,永久有效;但必须重新登陆的shell才生效

[root@yph7 ~]# hostnamectl set-hostname vbird
[root@yph7 ~]# cat /etc/hostname  -------查看配置文件里的名字是否改变
vbird
.........................重新登陆一下,下面可以看到新的主机名已经生效了
Hello,root Welcome to login,the time is 2015-12-27-21:55:46
[root@vbird ~]#

主机名的配置文件

centos6:/etc/sysconfig/network

centos7:/etc/hostname

 

 

配置DNS服务器指向:把ip地址解析成主机名或把主机名解析成ip地址

 

编辑配置文件:/etc/resolv.conf

nameserver   DNS_SERVER_IP

例如:nameserver 202.106.195.68

最多可配置三个

 

如何测试,看DNS是否生效(host/nslookup/dig):

hosts文件的作用:

[root@yph7 ~]# cat /etc/hosts 
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
172.16.0.1 www.baidu.com    g.cn  google

如上所示,修改hosts文件,在最后一行添加一个IP和主机的解析,并给172.16.0.1添加了好几个别名,从下面可以看出,我不论ping的是www.baidu.com,还是g.cn还是google最终都会解析到172.16.0.1这个主机上。只是这样一来就不能用www.baidu.com这个域名上百度了。

[root@yph7 ~]# ping www.baidu.com
PING www.baidu.com (172.16.0.1) 56(84) bytes of data. 
[root@yph7 ~]# ping g.cn
PING www.baidu.com (172.16.0.1) 56(84) bytes of data.
[root@yph7 ~]# ping google
PING www.baidu.com (172.16.0.1) 56(84) bytes of data.


dig  -t A  FQDN,把主机名解析成ip地址,直接拿ip地址也可以访问网站

[root@yph7 ~]# dig -t A www.magedu.com
   600 IN A 101.200.188.230

dig  -x  IP:将ip解析成主机名

不过大多网站都是进行这样反解析的,所以很可能不成功

 

iproute家族

iproute的版本号与内核是一一致的,因为iproute很多设置是直接放置到内核中去的。(想要验证版本号的话请用:rpm -qi iproute;查看内核版本用uname -r)

ip命令:

show / manipulaterouting, devices, policy routing and tunnels

 

ip  OBJECT:link、addr 、 route 、 netns 

 

ip link: network device configuration完成网络设备配置,查看帮助用ip link help

                         注意:    ip link set 可简写成ip li se

ip  link set- change device attributes管理设备属性

            dev NAME(default):指明要管理的设备,dev这个关键字可省略;

up和down:启用和禁用网卡

禁用网卡

[root@yph7 ~]# ip link set eno33554984 down
[root@yph7 ~]# ip link list
1: lo:  mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eno16777736:  mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000
    link/ether 00:0c:29:90:fa:11 brd ff:ff:ff:ff:ff:ff
3: eno33554984:  mtu 1500 qdisc pfifo_fast state DOWN mode DEFAULT qlen 1000
    link/ether 00:0c:29:90:fa:1b brd ff:ff:ff:ff:ff:ff

启用网卡

[root@yph7 ~]# ip link set eno33554984 up ----请用此网卡,“up”标志又回来了
[root@yph7 ~]# ip link list dev eno33554984
3: eno33554984:  mtu 1500 qdisc pfifo_fast state DOWN mode DEFAULT qlen 1000
    link/ether 00:0c:29:90:fa:1b brd ff:ff:ff:ff:ff:ff

multicast on或multicast off:启用或禁用多播功能;

禁用多播功能

[root@yph7 ~]# ip link set eno33554984 multicast off
[root@yph7 ~]# ip link show eno33554984 --------可看出多播功能已经关闭
3: eno33554984:  mtu 1500 qdisc pfifo_fast state DOWN mode DEFAULT qlen 1000
    link/ether 00:0c:29:90:fa:1b brd ff:ff:ff:ff:ff:ff

启用多播功能

[root@yph7 ~]# ip link set eno33554984 multicast on
[root@yph7 ~]# ip link list eno33554984  -----------可以看出多播功能又会来了
3: eno33554984:  mtu 1500 qdisc pfifo_fast state DOWN mode DEFAULT qlen 1000
    link/ether 00:0c:29:90:fa:1b brd ff:ff:ff:ff:ff:ff


name NAME:为网络接口重命名

[root@yph7 ~]# ip link set eno33554984 down --------改名前先禁用网卡
[root@yph7 ~]# ip link set eno33554984 name eno33333333
[root@yph7 ~]# ip link show  ------------------网卡重命名成功
1: lo:  mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eno16777736:  mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000
    link/ether 00:0c:29:90:fa:11 brd ff:ff:ff:ff:ff:ff
3: eno33333333:  mtu 1500 qdisc pfifo_fast state DOWN mode DEFAULT qlen 1000
    link/ether 00:0c:29:90:fa:1b brd ff:ff:ff:ff:ff:ff


mtu NUMBER:设置MTU的大小,默认为1500;

[root@yph7 ~]# ip link set eno33554984 mtu 1200
[root@yph7 ~]# ip link list eno33554984   -----------mtu已经变成1200了
3: eno33554984:  mtu 1200 qdisc pfifo_fast state DOWN mode DEFAULT qlen 1000
    link/ether 00:0c:29:90:fa:1b brd ff:ff:ff:ff:ff:ff

 

ip  link show  - display device attributes显示设备属性ip ; link help -  显示简要使用帮助。

 ip link list:用法与ip link show 相似

[root@yph7 ~]# ip link show      ----显示出所有网卡的状态,包括未启用的网卡
[root@yph7 ~]# ip link show eno33554984      -------显示指定网络接口的状态

ip netns:  - manage network namespaces.管理网络用户空间

 netns PID:ns为namespace,用于将接口移动到指定的网络名称空间;可用此方法构建非常复杂的虚拟网络。只有centos7可以用

ip  netns list:列出所有的netns;可以简写:ip link list或ip li li

ip  netns add  NAME:创建指定的netns

ip  netns del  NAME:删除指定的netns

ip  netns  exec  NAME  COMMAND:在指定的netns中运行命令

[root@yph7 ~]# ip netns add mynet --------添加新的网络名称空间
[root@yph7 ~]# ip netns list -------查看是否添加成功
mynet
[root@yph7 ~]# ip link show  -----------现在一共有两块网卡
1: lo:  mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eno16777736:  mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000
    link/ether 00:0c:29:90:fa:11 brd ff:ff:ff:ff:ff:ff
3: eno33333333:  mtu 1500 qdisc pfifo_fast state DOWN mode DEFAULT qlen 1000
    link/ether 00:0c:29:90:fa:1b brd ff:ff:ff:ff:ff:ff
[root@yph7 ~]# ip link set eno33333333 netns mynet ---将指定网卡移动到网络名称空间
[root@yph7 ~]# ip link show        ---------------现在只剩一块网卡,因为另一块被移走了
1: lo:  mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eno16777736:  mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000
    link/ether 00:0c:29:90:fa:11 brd ff:ff:ff:ff:ff:ff
[root@yph7 ~]# ip netns exec mynet ip link show ----类似进入虚拟世界执行ip link show命令
1: lo:  mtu 65536 qdisc noop state DOWN mode DEFAULT 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
3: eno33333333:  mtu 1500 qdisc noop state DOWN mode DEFAULT qlen 1000
    link/ether 00:0c:29:90:fa:1b brd ff:ff:ff:ff:ff:ff
[root@yph7 ~]# ip netns del mynet   -------------删除虚拟网络名称空间
[root@yph7 ~]# ip link show         -----------------我们的网卡又回到现实世界中来了
1: lo:  mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eno16777736:  mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000
    link/ether 00:0c:29:90:fa:11 brd ff:ff:ff:ff:ff:ff
3: eno33554984:  mtu 1500 qdisc pfifo_fast state DOWN mode DEFAULT qlen 1000
    link/ether 00:0c:29:90:fa:1b brd ff:ff:ff:ff:ff:ff


 

ip addr -protocol address management.管理ip网络接口地址

 

ip address add-add new protocol address添加新的协议地址

ip  addr add  IFADDR  dev IFACE

[root@yph7 apache2]# ip addr add 192.168.100.10/24 dev eth0
[root@yph7 apache2]# ip addr add 192.168.100.20/24 dev eth0
[root@yph7 apache2]# ip addr add 10.0.0.0/8 dev eth0   ---给eth0添加3个ip地址
[root@yph7 apache2]# ip addr show eth0
2: eth0:  mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:40:7c:9b brd ff:ff:ff:ff:ff:ff
    inet 192.168.100.10/24 scope global eth0
    inet 10.0.0.0/8 scope global eth0        ----------eth0有三个ip地址
    inet 192.168.100.20/24 scope global secondary eth0---为secondary,因为前面有了一个同一网段的ip
    inet6 fe80::20c:29ff:fe40:7c9b/64 scope link 
       valid_lft forever preferred_lft forever

label NAME:为额外添加的地址指明接口别名;给某一接口的ip地址都添加一个别名,用ifconfig命令才能查看到接口的所有ip。

[root@yph7 apache2]# ip addr add 192.168.100.1 dev eth0 
[root@yph7 apache2]# ip addr add 192.168.100.2 dev eth0 label eth0:0
[root@yph7 apache2]# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:0C:29:40:7C:9B  
          inet addr:192.168.100.1  Bcast:0.0.0.0  Mask:255.255.255.255---没指定掩码的结果
    ......................................................
eth0:0    Link encap:Ethernet  HWaddr 00:0C:29:40:7C:9B  
          inet addr:192.168.100.2  Bcast:0.0.0.0  Mask:255.255.255.255
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1


broadcast ADDRESS:广播地址;会根据IP和NETMASK自动计算得到,所以一般不用我们手动设定

scope SCOPE_VALUE:下面是scope的三个选项

global:全局可用;别人可以ping通

link:接口可用;别人ping不通,自己可以ping通

host:仅本机可用;除本主机以外的主机看不到这个ip


名称栏目:CentOs网络管理:ifconfig家族,iproute家族及配置文件
URL链接:http://bjjierui.cn/article/jijdeh.html

其他资讯