ip命令:

ip link管理接口/链接命令:

        ip link help                          查看帮助信息

        ip link shwo                         查看网卡简要信息

        ip link show eth0                 显示单个网卡信息

        ip link show up                    显示激活状态的接口

开启或关闭:

        ip link set dev eth0 up         开启接口eth0

        ip link set dev eth0 down    禁用接口eth0

        Tips:在CentOS6上网卡是以网卡命名的方式,在CentOS7上网卡名称是以插槽的来命名。

例:ip link show 

        [root@qiyang-2 ~]# ip link show

        1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN 

            link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

        2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000

            link/ether 00:0c:29:68:24:98 brd ff:ff:ff:ff:ff:ff

                尖括号<>里面的表示已经启用的属性。

                BROADCAST        支持广播

                MULTICAST          支持主播或多播

                UP                         启用状态

                mtu                       最大协议传输单元

                pfifo_fast              流控算法机制

                qlen                      传输队列个数

                link/ether              MAC地址

                brd                        广播地址


ip addr管理地址:

        ip addr help         查看帮助

        ip addr show        显示地址

        ip addr show dev eth0                                     显示指定地址

添加IP地址:

        ip addr add 192.168.96.127/24 dev eth0        向某个端口中添加地址,这个端口会有两个地址

        ip addr add 192.168.96.138/24 dev ens33 label ens33:0

替换IP地址:

        ip addr replace 192.168.96.127/24 dev eth0   替换

删除IP地址:

        ip addr del 192.168.96.128/24 dev eth0          删除某个网卡地址

        ip addr add 192.168.96.128/24 dev eth0 label 'labelname'        添加并指定别名


        scope      global全局可用,link一个端口可用,host本机可用

        

ip route管理路由:

        ip route add 192.168.96.128 via 192.168.96.128  dev eth0        添加主机路由,vai网关,dev设备名

        ip route delete 192.168.96.128/24        删除网关

        ip route show        显示

        ip route flush        刷新


ss查看网络状态命令,比netstat快

ss命令:

        格式:ss [OPTION]... [FILTER]

        选项:

                -t: tcp协议相关

                -u: udp协议相关

                -w: 裸套接字相关

                -x:unix sock相关

                -l: listen状态的连接

                -a: 所有

                -n: 数字格式

                -p: 相关的程序及PID

                -e: 扩展的信息

                -m:内存用量

                -o:计时器信息

                常用组合:-tan, -tanl, -tanlp, -uan


配置文件目录:

        IP、MASK、GW、DNS相关配置文件:/etc/sysconfig/network-scripts/ifcfg-IFACE

        路由相关的配置文件:/etc/sysconfig/network-scripts/route-IFACE        这个文件默认不存在,手动创建


        网卡配置文件注释:

        /etc/sysconfig/network-scripts/ifcfg-IFACE:

                DEVICE:此配置文件应用到的设备;

                HWADDR:对应的设备的MAC地址;

                BOOTPROTO:激活此设备时使用的地址配置协议,常用的dhcp, static, none, bootp;

                NM_CONTROLLED:NM是NetworkManager的简写;此网卡是否接受NM控制;CentOS6建议为“no”;

                ONBOOT:在系统引导时是否激活此设备;

                TYPE:接口类型;常见有的Ethernet, Bridge;

                UUID:设备的惟一标识;

                IPADDR:指明IP地址;

                NETMASK:子网掩码;

                GATEWAY: 默认网关;

                DNS1:第一个DNS服务器指向;这个DNS会比/etc/resolv.conf优先级要高

                DNS2:第二个DNS服务器指向;

                USERCTL:普通用户是否可控制此设备;

                PEERDNS:如果BOOTPROTO的值为“dhcp”,是否允许dhcp server分配的dns服务器指向信息直接覆盖至/etc/resolv.conf文件中,(DHCP可以分配IP、掩码、网关、DNS)

                例:

                DEVICE=eth0

                HWADDR=00:0C:29:68:24:98

                TYPE=Ethernet

                UUID=fb08cf34-751b-4496-8190-b2983491b1f0

                ONBOOT=yes

                NM_CONTROLLED=yes

                BOOTPROTO=dhcp

                GATEWAY=192.168.96.2

                IPADDR=192.168.96.128

                NETMASK=255.255.255.0

                DNS1=192.168.1.1


        配置路由的方法:

        /etc/sysconfig/network-scripts/route-IFACE

                两种风格:

                        (1) TARGET via GW

                                例:192.168.96.128/24  via 192.168.96.2

                        (2) 每三行定义一条路由

                                ADDRESS#=TARGET    这里的#代表数字

                                NETMASK#=mask

                                GATEWAY#=GW


配置主机名:

        hostname               查看主机名

        hostname  name    配置主机名

        永久修改主机名:

            vim /etc/sysconfig/network        

                    NETWORKING=yes            网络总开关

                    HOSTNAME=qiyang-2       主机名

/etc/udev/rules.d/70-persistent-net.rules        这个配置文件可修改网络接口命名

卸载网卡驱动:modprobe -r e1000

卸载网卡驱动:modprobe e1000