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

相关推荐

  • 文件管理基础知识及命令详解

    文件系统     文件和目录被组织成一个单根倒置树结构     文件系统从根目录下开始,用“ /”表示     根文件系统(rootfs): root filesystem    …

    Linux干货 2016-08-05
  • Linux基础之sed流编辑器详解

    之前介绍了三大文本编辑器的grep,这里介绍比grep功能更强的sed流编辑器 sed是什么? sed是Stream EDitor的缩写,man中对sed的简介为 sed – stream editor for filtering and transforming text 它的主要功能是对文本的过滤与替换。 sed的工作原理 sed的工作过程:…

    Linux干货 2016-08-15
  • linux 网络管理

    1、ifconfig命令格式: ifconfig[interface] 查看IP ifconfig-a 查看全部网卡信息 ifconfigIFACE [up|down] 网卡开启关闭 ifconfigIFACE IP/netmask [up] ifconfigIFACE IP netmask NETMASK 命令立即生效,不能永久保存  &nbsp…

    Linux干货 2017-08-20
  • HAproxy实战

    HAproxy实验一 1、实验要求: (1) 动静分离discuzx,动静都要基于负载均衡实现; (2) 进一步测试在haproxy和后端主机之间添加varnish缓存(见实验二步骤); (3) 给出拓扑设计; (4) haproxy的设定要求: (a) 启动stats; (b) 自定义403、502和503的错误页; (c) 各组后端主机选择合适的调度方法…

    Linux干货 2016-11-15
  • VimTutor(上)

    柚子翻译,如有理解错误或翻译错误,请指正! VimTutor Vim是一款强大的文本编辑器,拥有多命令的特性,tutor解释了其中大多数命令。 tutor是为了描述足够多的Vim命令帮助你轻松使用Vim而被制作的,使Vim能成为一个可完成你所有工作意图的编辑器。 完成tutor的内容大概需要25-30分钟,所完成时间取决于你通过时间积累的经验。 注意: 1.…

    Linux干货 2015-10-18
  • iptables

    规则格式:iptables   [-t table]   COMMAND   chain   [-m matchname [per-match-options]]   -j targetname [per-target-options]     -t table:&nb…

    Linux干货 2017-06-16