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)
上一篇 2016-07-07 10:53
下一篇 2016-07-07 19:06

相关推荐

  • 用户、组及文件相关的一些命令

    1、复制/etc/skel目录为/home/tuser1,要求/home/tuser1及其内部文件的属组和其他用户均没有任何访问权限。 cp -r /etc/skel /home/tuser1,因为是目录文件所以要有-r ls -ld /etc/skel chmod 000 -R /home/tuser1 ls -al /home/tuser1/ 2、编辑/…

    2017-07-23
  • LAMP 通过使用脚本的方式安装并部署Discuz

    该脚本有很多辅助的部分,主要是为了让脚本在中途运行失败可以多次运行,所产生的结果是预期的,与第一运行并成功的结果是一样的。初次摄入bash脚本有很多不足,敬请指正。 所需要的软件 apr-1.5.2.tar.bz2 apr-util-1.5.4.tar.bz2 Discuz_X3.2_SC_UTF8.zip freetype-2.5.4.tar.gz htt…

    Linux干货 2016-04-05
  • DHCP

        动态主机设置协议(Dynamic Host Configuration Protocol,DHCP)是一个局域网的网络协议,使用UDP协议工作,主要有两个用途: 用于内部网络或网络服务供应商自动分配IP地址给用户 用于内部网络管理员作为对所有电脑作中央管理的手段     …

    Linux干货 2017-07-24
  • ntp时间服务器搭建实例

    ntp时间服务器采用stratum分级架构来处理时间同步;举例说明:你搭建了一台ntp服务器,然后同步的server为stratum-1,你的ntp则为stratum-2,你的下级ntp则为tratum-3。依此类推,最多为15层。 1.ntp server安装: [root@localhost ~]# yum -y …

    Linux干货 2015-11-10
  • 从Linux小白到大牛——与狼共舞的日子4

    马哥教育网络班21期+第4周课程练习 1、复制/etc/skel目录为/home/tuser1,要求/home/tuser1及其内部文件的属组和其它用户均没有任何访问权限。 [root@localhost ~]# cp -a /etc/skel/ /home/tuser1/ [root@localhost&n…

    Linux干货 2016-08-02
  • 第二天作业

    一、Linux 文件管理类命令   cd、pwd、mkdir、rmdir、ls、cp、rm、mv、cat、tac、more、less、head、tail、touch     1、目录类相关命令     cd:change directory 切换目录     pwd:print …

    Linux干货 2016-08-22