Linux网络属性管理(二)

Linux网络属性(二)

Linux 网络属性管理(二)


ip命令

ip - show / manipulate routing, devices, policy routing and tunnels
ip [ OPTIONS ] OBJECT { COMMAND | help }

    OBJECT := { link | addr | route }

        link OBJECT:

ip link – network device configuration

    set
        dev IFACE
             可设置属性:
             up and down:激活或禁用指定接口;

        show
            [dev IFACE]:指定接口
            [up]:仅显示处于激活状态的接口

显示当前的ip链接

[root@Daniel ~]# ip link show 
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 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:2c:81:4d brd ff:ff:ff:ff:ff:ff

ip address – protocol address management

    ip addr { add | del } IPADDR dev STRING
        [label LABEL]:添加地址时指明网卡别名
        [scope {global|link|host}]:指明作用域
            global: 全局可用;
            link: 仅链接可用;
            host: 本机可用;
        [broadcast ADDRESS]:指明广播地址

显示ip地址

[root@Daniel ~]# ip addr show 
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host 
   valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:2c:81:4d brd ff:ff:ff:ff:ff:ff
inet 192.168.98.140/24 brd 192.168.98.255 scope global eth0
inet6 fe80::20c:29ff:fe2c:814d/64 scope link 
   valid_lft forever preferred_lft forever

为eth0这块儿网卡添加一个地址并赋予别名eth0:0

[root@Daniel ~]# ip addr add 192.168.98.141/24 dev eth0 label eth0:0 
[root@Daniel ~]# ip add show eth0 
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:2c:81:4d brd ff:ff:ff:ff:ff:ff
inet 192.168.98.140/24 brd 192.168.98.255 scope global eth0
inet 192.168.98.141/24 scope global secondary eth0:0
inet6 fe80::20c:29ff:fe2c:814d/64 scope link 
   valid_lft forever preferred_lft forever

删除刚才添加的地址

[root@Daniel ~]# ip addr del 192.168.98.141/24 dev eth0 
[root@Daniel ~]# ip addr show 
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host 
   valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:2c:81:4d brd ff:ff:ff:ff:ff:ff
inet 192.168.98.140/24 brd 192.168.98.255 scope global eth0
inet6 fe80::20c:29ff:fe2c:814d/64 scope link 
   valid_lft forever preferred_lft forever

ip address show – look at protocol addresses

        [dev DEVICE]
        [label PATTERN]
        [primary and secondary]

[root@Daniel ~]# ip address show 
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host 
   valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:2c:81:4d brd ff:ff:ff:ff:ff:ff
inet 192.168.98.140/24 brd 192.168.98.255 scope global eth0
inet 192.168.98.141/24 scope global secondary eth0:0
inet6 fe80::20c:29ff:fe2c:814d/64 scope link 
   valid_lft forever preferred_lft forever
[root@Daniel ~]# ip address show label eth0:0 
inet 192.168.98.141/24 scope global secondary eth0:0

ip address flush – flush protocol addresses

        使用格式同show

ip route – routing table management

        ip route add
        添加路由:ip route add TARGET via GW dev IFACE src SOURCE_IP
            TARGET:
                主机路由:IP
                网络路由:NETWORK/MASK

[root@Daniel ~]# ip route add 192.168.1.3 via 192.168.98.2 dev eth0 
[root@Daniel ~]# 
[root@Daniel ~]# ip route show 
192.168.1.3 via 192.168.98.2 dev eth0 
192.168.98.0/24 dev eth0  proto kernel  scope link  src 192.168.98.140 
169.254.0.0/16 dev eth0  scope link  metric 1002 
default via 192.168.98.2 dev eth0 
[root@Daniel ~]# ip route add 192.168.0.0/24 via 192.168.98.2 
[root@Daniel ~]# 
[root@Daniel ~]# ip route show 
192.168.1.3 via 192.168.98.2 dev eth0 
192.168.98.0/24 dev eth0  proto kernel  scope link  src 192.168.98.140 
192.168.0.0/24 via 192.168.98.2 dev eth0 
169.254.0.0/16 dev eth0  scope link  metric 1002 
default via 192.168.98.2 dev eth0 


        添加网关:ip route add defalt via GW dev IFACE



        ip route delete
        删除路由:ip route del TARGET 

[root@Daniel ~]# ip route del 192.168.1.3 
[root@Daniel ~]# 
[root@Daniel ~]# ip route show 
192.168.98.0/24 dev eth0  proto kernel  scope link  src 192.168.98.140 
192.168.0.0/24 via 192.168.98.2 dev eth0 
169.254.0.0/16 dev eth0  scope link  metric 1002 
default via 192.168.98.2 dev eth0 
[root@Daniel ~]# ip route del 192.168.0.0/24 
[root@Daniel ~]# ip route show 
192.168.98.0/24 dev eth0  proto kernel  scope link  src 192.168.98.140 
169.254.0.0/16 dev eth0  scope link  metric 1002 
default via 192.168.98.2 dev eth0 


        ip route show

[root@Daniel ~]# ip route show 
192.168.98.0/24 dev eth0  proto kernel  scope link  src 192.168.98.140 
169.254.0.0/16 dev eth0  scope link  metric 1002 
default via 192.168.98.2 dev eth0 

        ip route flush  清空路由表
            [dev IFACE]
            [via PREFIX]

ss命令

ss命令:

格式:ss [OPTION]... [FILTER]
    选项:
        -t: tcp协议相关
        -u: udp协议相关
        -w: 裸套接字相关
        -x:unix sock相关
        -l: listen状态的连接
        -a: 所有
        -n: 数字格式
        -p: 相关的程序及PID
        -e: 扩展的信息
        -m:内存用量
        -o:计时器信息

        FILTER := [ state TCP-STATE ] [ EXPRESSION ]

TCP的常见状态:

tcp finite state machine:
        LISTEN: 监听
        ESTABLISHED:已建立的连接
        FIN_WAIT_1
        FIN_WAIT_2
        SYN_SENT
        SYN_RECV
        CLOSED

    EXPRESSION:
        dport = 
        sport = 
        示例:’( dport = :ssh or sport = :ssh )’

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

[root@Daniel ~]# ss -tan 
State      Recv-Q Send-Q                                        Local Address:Port                                          Peer Address:Port 
LISTEN     0      128                                                      :::22                                                      :::*     
LISTEN     0      128                                                       *:22                                                       *:*     
LISTEN     0      100                                                     ::1:25                                                      :::*     
LISTEN     0      100                                               127.0.0.1:25                                                       *:*     
ESTAB      0      0                                            192.168.98.140:22                                            192.168.98.1:64234 
ESTAB      0      0                                            192.168.98.140:22                                            192.168.98.1:55255 
[root@Daniel ~]# 

[root@Daniel ~]# ss -tanl 
State      Recv-Q Send-Q                                        Local Address:Port                                          Peer Address:Port 
LISTEN     0      128                                                      :::22                                                      :::*     
LISTEN     0      128                                                       *:22                                                       *:*     
LISTEN     0      100                                                     ::1:25                                                      :::*     
LISTEN     0      100                                               127.0.0.1:25                                                       *:*     
[root@Daniel ~]#

原创文章,作者:Daniel-W,如若转载,请注明出处:http://www.178linux.com/22987

赞 (1)
Daniel-WDaniel-W
上一篇 2016-07-07 10:53
下一篇 2016-07-07 19:06

相关推荐

  • CentOS系统启动流程

        Linux系统的组成部分   1、动态视角:内核+根文件系统  2、静态视角:磁盘分区+文件 Linux运行中的系统环境   1、用户空间:应用程序(进程或线程)  2、内核空间:内核代码(系统调用) 内核设计流派:   *单内核设计:把所有功能集成于同一个程序,如:Linux  *微内核设计:每种功能使用一个单独的子系统实现,如…

    Linux干货 2016-12-30
  • 磁盘管理之文件系统

    一,概述 文件系统是操作系统用于明确存储设备或分区上的文件的方 法和数据结构;即在存储设备上组织文件的方法。操作系统 中负责管理和存储文件信息的软件结构称为文件管理系统, 简称文件系统。  从系统角度来看,文件系统是对文件存储设备的空间进行组 织和分配,负责文件存储并对存入的文件进行保护和检索的 系统。具体地说,它负责为用户建立文件,存入、读出、修…

    Linux干货 2016-09-05
  • 软件包管理

    软件运行环境 ABI(应用程序的二进制接口):Application Binary Interface Windows 与Linux 不兼容 ELF(Executable and Linkable Format)           —&…

    Linux干货 2017-04-23
  • Linux计算机基础及Linux入门

    计算机,Linux发型版,Linux 哲学思想,基本命令,startx ,pwd tty ,shutdown ,ifconfig , echo, export, historybo, poweroff,reboot, date, hwclock, Linux 获取命令帮助信息,Linux发行版的基础目录,

    2017-09-18
  • 系统基础之AWK详解

    GUN awk 文本处理三工具:grup,sed,awk     grep,egrep,fgrep:文本过滤工具     sed:行编辑器         模式空间,保持空间   …

    Linux干货 2016-09-21
  • grep命令和find命令的练习

    1、显示系统上root、Fedora、或user1用户的默认shell [root@localhost ~]# grep -E “^(root|fedora|user1)\>” /etc/passwd | cut -d: -f1,7 root:/bin/bash fedora:/bin/bash user1:/bin/bash 2、找出/etc/rc.…

    Linux干货 2017-07-30