Linux网络配置(2)

Linux网络配置(2)

配置Linux网络属性:ip命令
使用rpm -qf查看版本安装IP命令:
[root@localhost ~]# rpm -qf `which ip`
iproute-2.6.32-23.el6.x86_64

ip命令:
    ip - show / manipulate routing, devices, policy routing and tunnels
        ip [ OPTIONS ] OBJECT { COMMAND | help }
        OBJECT := { link | addr | route }

[root@localhost ~]# ip link help-->主要管理二层信息:
Usage: ip link add link DEV [ name ] NAME
 [ txqueuelen PACKETS ]
 [ address LLADDR ]
 [ broadcast LLADDR ]
 [ mtu MTU ]
type TYPE [ ARGS ]
  ip link delete DEV type TYPE [ ARGS ]
ip link set DEVICE [ { up | down } ]
   [ arp { on | off } ]
   [ dynamic { on | off } ]
   [ multicast { on | off } ]
   [ allmulticast { on | off } ]
   [ promisc { on | off } ]
   [ trailers { on | off } ]
   [ txqueuelen PACKETS ]
   [ name NEWNAME ]
   [ address LLADDR ]
   [ broadcast LLADDR ]
   [ mtu MTU ]
   [ netns PID ]
   [ alias NAME ]
   [ vf NUM [ mac LLADDR 
   [ vlan VLANID [ qos VLAN-QOS ] ]
   [ rate TXRATE ] ] 
 ip link show [ DEVICE ]

TYPE := { vlan | veth | vcan | dummy | ifb | macvlan | can }

ip link下的2个子命令:set ,show
    set
    dev IFACE
    可设置属性:
    up and down:激活或禁用指定接口;
[root@localhost ~]# ip link set lo up

[root@localhost ~]# ip link show up
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 08:00:27:b5:54:45 brd ff:ff:ff:ff:ff:ff


show
    [dev IFACE]:指定接口
[root@localhost ~]# ip link show eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 08:00:27:b5:54:45 brd ff:ff:ff:ff:ff:ff

    [up]:仅显示处于激活状态的接口
[root@localhost ~]# ip link show
1: lo: <LOOPBACK> mtu 16436 qdisc noqueue state DOWN 
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 08:00:27:b5:54:45 brd ff:ff:ff:ff:ff:ff
[root@localhost ~]# ip link show up
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 08:00:27:b5:54:45 brd ff:ff:ff:ff:ff:ff

ip address - protocol address management -->协议地址的管理工具!

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

ip address show - look at protocol addresses-->清空地址:
    [dev DEVICE]
    [label PATTERN]
    [primary and secondary]

ip route - routing table management-->路由表管理:
    ip route add
    添加路由:ip route add TARGET via GW dev IFACE src SOURCE_IP
        TARGET:
            主机路由:IP
            网络路由:NETWORK/MASK
    添加网关:ip route add defalt via GW dev IFACE

[root@localhost ~]# ip route show
192.168.1.0/24 dev eth0  proto kernel  scope link  src 192.168.1.3  metric 1 


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

ip route flush:清空路由表

ss命令:网络状态查看工具

格式:ss [OPTION]... [FILTER]
    选项:
        -t: tcp协议相关
[root@localhost ~]# ss -t
State      Recv-Q Send-Q             Local Address:Port                 Peer Address:Port   
ESTAB      0      0                    192.168.1.3:ssh                   192.168.1.2:50255   
ESTAB      0      0                    192.168.1.3:ssh                   192.168.1.2:50247   
ESTAB      0      52                   192.168.1.3:ssh                   192.168.1.2:50259   

        -u: udp协议相关
[root@localhost ~]# ss -u
State      Recv-Q Send-Q             Local Address:Port                 Peer Address:Port   

        -w: 裸套接字相关
        -x:unix sock相关
        -l: listen状态的连接
        -a: 所有
[root@localhost ~]# ss -a
State      Recv-Q Send-Q             Local Address:Port                 Peer Address:Port   
LISTEN     0      128                           :::sunrpc                         :::*       
LISTEN     0      128                            *:sunrpc                          *:*       
LISTEN     0      128                           :::ssh                            :::*       
LISTEN     0      128                            *:ssh                             *:*       
LISTEN     0      128                           :::34710                          :::*       
LISTEN     0      128                    127.0.0.1:ipp                             *:*       
LISTEN     0      128                          ::1:ipp                            :::*       
LISTEN     0      100                          ::1:smtp                           :::*       
LISTEN     0      100                    127.0.0.1:smtp                            *:*       
LISTEN     0      128                            *:34265                           *:*       
ESTAB      0      0                    192.168.1.3:ssh                   192.168.1.2:50255   
ESTAB      0      0                    192.168.1.3:ssh                   192.168.1.2:50247   
ESTAB      0      52                   192.168.1.3:ssh                   192.168.1.2:50259   

        -n: 数字格式
[root@localhost ~]# ss -n
State      Recv-Q Send-Q               Local Address:Port                 Peer Address:Port 
ESTAB      0      0                      192.168.1.3:22                    192.168.1.2:50255 
ESTAB      0      0                      192.168.1.3:22                    192.168.1.2:50247 
ESTAB      0      52                     192.168.1.3:22                    192.168.1.2:50259 

        -p: 相关的程序及PID
[root@localhost ~]# ss -p
State      Recv-Q Send-Q             Local Address:Port                 Peer Address:Port   
ESTAB      0      0                    192.168.1.3:ssh                   192.168.1.2:50255    users:(("sshd",2934,3))
ESTAB      0      0                    192.168.1.3:ssh                   192.168.1.2:50247    users:(("sshd",2911,3))
ESTAB      0      52                   192.168.1.3:ssh                   192.168.1.2:50259    users:(("sshd",2958,3))

        -e: 扩展的信息
[root@localhost ~]# ss -e
State      Recv-Q Send-Q             Local Address:Port                 Peer Address:Port   
ESTAB      0      0                    192.168.1.3:ssh                   192.168.1.2:50255    timer:(keepalive,67min,0) ino:21235 sk:ffff88003d68d480
ESTAB      0      0                    192.168.1.3:ssh                   192.168.1.2:50247    timer:(keepalive,67min,0) ino:21105 sk:ffff880037e7e080
ESTAB      0      52                   192.168.1.3:ssh                   192.168.1.2:50259    timer:(on,414ms,0) ino:21365 sk:ffff88003d68ce00

        -m:内存用量
[root@localhost ~]# ss -m
State      Recv-Q Send-Q             Local Address:Port                 Peer Address:Port   
ESTAB      0      0                    192.168.1.3:ssh                   192.168.1.2:50255   
     mem:(r0,w0,f4096,t0)
ESTAB      0      0                    192.168.1.3:ssh                   192.168.1.2:50247   
     mem:(r0,w0,f4096,t0)
ESTAB      0      52                   192.168.1.3:ssh                   192.168.1.2:50259   
     mem:(r0,w1332,f2764,t0)

        -o:计时器信息
[root@localhost ~]# ss -o
State      Recv-Q Send-Q             Local Address:Port                 Peer Address:Port   
ESTAB      0      0                    192.168.1.3:ssh                   192.168.1.2:50255    timer:(keepalive,66min,0)
ESTAB      0      0                    192.168.1.3:ssh                   192.168.1.2:50247    timer:(keepalive,66min,0)
ESTAB      0      52                   192.168.1.3:ssh                   192.168.1.2:50259    timer:(on,388ms,0)


FILTER := [ state TCP-STATE ] [ EXPRESSION ]-->自己指明表达式:

[root@localhost ~]# ss -tan state ESTABLISHED
Recv-Q Send-Q                    Local Address:Port                      Peer Address:Port 
0      0                           192.168.1.3:22                         192.168.1.2:50255 
0      0                           192.168.1.3:22                         192.168.1.2:50247 
0      52                          192.168.1.3:22                         192.168.1.2:50259 

TCP的常见状态:
    tcp finite state machine:
        LISTEN: 监听
        ESTABLISHED:已建立的连接
        FIN_WAIT_1:断开   
        FIN_WAIT_2:断开
        SYN_SENT:三次握手一次
        SYN_RECV:三次握手第二次
        CLOSED:
    TCP三次握手-->四次断开!!!

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


EXPRESSION:
    dport = 
    sport = 
示例:ss -o state established ’( dport = :ssh or sport = :ssh )’

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

(0)
wostopwostop
上一篇 2016-08-02
下一篇 2016-08-02

相关推荐

  • N28 第三周【1】:grep和文本处理工具的使用

    grep一些练习 1、列出当前系统上所有已经登录的用户的用户名,注意:同一个用户登录多次,则只显示一次即可。 [root@localhost ~]# who |cut -d” ” -f1 |sort -u root 2、取出最后登录到当前系统的用户的相关信息。 [root@localhost ~]# last |cut -d” ” -f1|head -1 |…

    Linux干货 2017-12-19
  • HAProxy

    HAProxy简介 HAProxy是免费、极速且可靠的用于为TCP和基于HTTP应用程序提供高可用、负载均衡和代理服务的解决方案,尤其适用于高负载且需要持久连接或7层处理机制的web站点。HAProxy还可以将后端的服务器与网络隔离,起到保护后端服务器的作用。HAProxy的负载均衡能力虽不如LVS,但也是相当不错,而且由于其工作在7层,可以对http请求报…

    2017-05-17
  • linux系统的路由功能

    1、概要    大家应该都明白,不同网段的报文包传播,是需要路由的转发转发功能的,那么,一个linux操作系统能不能充当路由器呢?下面不妨来验证一下。 2、网络拓扑 3、实现过程    <1>俩个centos6分别充当Router1和Router2。并添加足够的网卡。    <2&…

    Linux干货 2016-09-06
  • 配置逻辑卷·设定LVM快照·btrfs文件系统

    _ueditor_page_break_tag_ 配置逻辑卷,设定LVM快照,btrfs文件系统                 逻辑卷管理器( LVM)v允许对卷进行方便操作的抽象层,包括重新设定文…

    Linux干货 2016-09-01
  • 文件查找工具—find命令总结

    描述:   find命令用来在指定目录下查找文件。任何位于参数之前的字符串都将被视为欲查找的目录名。如果使用该命令时,不设置任何参数,则find命令将在当前目录下查找子目录与文件。并且将查找到的子目录和文件全部进行显示。 说明:  工作特点:  查找速度略慢; 精确查找;实时查找;可能只搜索用户具备读取和执行权限的目录…

    Linux干货 2016-08-18
  • wordpress配置安装

    1、首先进行lamp框架的搭建 服务器环境:Linux Centos 7.2.1511 64位 内存:2G  磁盘空间100GB IP地址:10.55.10.79 进行httpd,php,php-mysql,mariadb-server的安装,安装均使用yum安装 ~]# yum -y install httpd php php-mysql mar…

    Linux干货 2016-11-04