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

相关推荐

  • 利用nginx实现基于传输层的四层负载均衡

    nginx利用ngx_stream_core_module实现四层的负载均衡服务。作为四层负载均衡nginx和lvs的区别在于: lvs工作于内核层,相对来说效率更高,性能更强; nginx工作于用户空间; lvs不会受到套接字数量的限制; nginx作为四层负载均衡也需要监听套接字来和客户端,后台服务器进行连接,会受到套接字数量限制,不过这个问题可以通过k…

    2017-07-03
  • 系统启动流程

    CentOS 5和6的启动流程服务管理Grub管理自制Linux启动排错编译安装内核 系统启动流程:  POST –> 读取BootSequence (BIOS),决定引导次序 –>读取引导设备的Bootloader(MBR grubstage1–>stage1.5/boot…

    Linux干货 2016-09-13
  • 一次css页面加载异常的折腾

    1       原始需求 近期在搭建平台,因多域名会分割流量,所以希望将类似 ansible.178linux.com  salt.178linux.com qa.178linux.com 这些平台整合为一个平台,所示如下 ansible.178linux.com =è www.178li…

    系统运维 2015-06-10
  • LNMMP架构实现Web动静分离

    前言 前面的文章中说过LAMP架构包括:Linux操作系统,Apache网站服务器,MySQL数据库,Perl、PHP或者Python编程语言,而今天要说的LNMMP 和LAMP类似,只是作为Web服务器的不再是Apache而是高性能的Nginx,同时引进Memcached加速缓存效率,用于加快访问速度。 Memcached是一款开源、高性能、分布…

    Linux干货 2015-06-15
  • 马哥教育网络班22期第3周课程作业

    1、列出当前系统上所有已经登录的用户的用户名,注意:同一个用户登录多次,则只显示一次即可。 [root@MyCloudServer ~]# who | cut -d " " -f1 |sort -u root 2、取出最后登录到当前系统的用…

    Linux干货 2016-09-19
  • 马哥教育网络班22期-第13周博客作业

    第13周博客作业 1、建立samba共享,共享目录为/data,要求:(描述完整的过程)   1)共享名为shared,工作组为zhucke;   2)添加组develop,添加用户gentoo,centos和ubuntu,其中gentoo和centos以develop为附加组,ubuntu不属于develop组;密码均为用户名; &nb…

    Linux干货 2016-12-26