Linux网络属性配置—iproute命令家族

ip命令:
show / manipulate routing, devices, policy routing and tunnels
ip [ OPTIONS ] OBJECT { COMMAND | help }
OBJECT := { link | addr | route | netns  }
ip  OBJECT:
ip link: network device configuration
         ip  link  show  – display device attributes
  1. ]# ip link show
  2. 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
  3. link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
  4. 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
  5. link/ether 00:0c:29:ae:e4:d8 brd ff:ff:ff:ff:ff:ff
  6. 3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
  7. link/ether 00:0c:29:ae:e4:e2 brd ff:ff:ff:ff:ff:ff
ip  link  set – change device attributes
dev NAME (default):指明要管理的设备,dev关键字可省略;
up和down:
multicast on或multicast off:启用或禁用多播功能;
name NAME:重命名接口
mtu NUMBER:设置MTU的大小,默认为1500;
netns PID:ns为namespace,用于将接口移动到指定的网络名称空间;
  1. ]# ip link set eth1 down
  2. ]# ip link show eth1
  3. 3: eth1: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast state DOWN qlen 1000
  4. link/ether 00:0c:29:ae:e4:e2 brd ff:ff:ff:ff:ff:ff
  5. ]# ip link set eth1 multicast off ]# ip link show eth1 3: eth1: <BROADCAST> mtu 1500 qdisc pfifo_fast state DOWN qlen 1000 link/ether 00:0c:29:ae:e4:e2 brd ff:ff:ff:ff:ff:ff
  1. ]# ip link set eth1 name exxx
  2. ]# ip link show
  3. 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
  4. link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
  5. 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
  6. link/ether 00:0c:29:ae:e4:d8 brd ff:ff:ff:ff:ff:ff
  7. 3: exxx: <BROADCAST> mtu 1500 qdisc pfifo_fast state DOWN qlen 1000
  8. link/ether 00:0c:29:ae:e4:e2 brd ff:ff:ff:ff:ff:ff
  1. ]# ip link set eth1 mtu 2000
  2. ]# ip link show eth1
  3. 3: eth1: <BROADCAST> mtu 2000 qdisc pfifo_fast state DOWN qlen 1000
  4. link/ether 00:0c:29:ae:e4:e2 brd ff:ff:ff:ff:ff:ff
ip  link  help –  显示简要使用帮助;
ip netns:  – manage network namespaces.
ip  netns  list:列出所有的netns
ip  netns  add  NAME:创建指定的netns
ip  netns  del  NAME:删除指定的netns
ip  netns   exec  NAME  COMMAND:在指定的netns中运行命令
  1. ]# ip netns list
  2. ]# ip netns add netspace
  3. ]# ip netns list
  4. netspace
ip address – protocol address management.
ip address add – add new protocol address
                ip address { add | del } IFADDR dev STRING
        ip address { show | flush } [ dev STRING ] [label PATTERN ]
ip  addr  add  IFADDR  dev  IFACE
[label NAME]:为额外添加的地址指明接口别名;
[broadcast ADDRESS]:广播地址;会根据IP和NETMASK自动计算得到;
[scope SCOPE_VALUE]:
global:全局可用;
link:接口可用;
host:仅本机可用;
  1. ]# ip addr add 192.168.1.10/24 dev eno16777736
  2. ]# ip addr show eno16777736
  3. 2: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
  4. link/ether 00:0c:29:60:1e:7a brd ff:ff:ff:ff:ff:ff
  5. inet 10.0.1.20/24 brd 10.0.1.255 scope global eno16777736
  6. valid_lft forever preferred_lft forever
  7. inet 192.168.1.10/24 scope global eno16777736
  8. valid_lft forever preferred_lft forever
  1. ]# ip addr add 192.168.2.10/24 dev eno16777736 label eno16777736:0
  2. ]# ip addr show eno16777736
  3. 2: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
  4. link/ether 00:0c:29:60:1e:7a brd ff:ff:ff:ff:ff:ff
  5. inet 10.0.1.20/24 brd 10.0.1.255 scope global eno16777736
  6. valid_lft forever preferred_lft forever
  7. inet 192.168.1.10/24 scope global eno16777736
  8. valid_lft forever preferred_lft forever
  9. inet 192.168.2.10/24 scope global eno16777736:0
  10. valid_lft forever preferred_lft forever
ip address delete – delete protocol address
ip addr  delete  IFADDR  dev  IFACE 
  1. ]# ip addr del 192.168.2.10/24 dev eno16777736
  2. ]# ip addr del 192.168.1.10/24 dev eno16777736
  3. ]# ip ad sh eno16777736
  4. 2: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
  5. link/ether 00:0c:29:60:1e:7a brd ff:ff:ff:ff:ff:ff
  6. inet 10.0.1.20/24 brd 10.0.1.255 scope global eno16777736
  7. valid_lft forever preferred_lft forever
ip address show – look at protocol addresses
ip  addr   list  [IFACE]:显示接口的地址;
  1. ]# ip addr show eno16777736
  2. 2: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
  3. link/ether 00:0c:29:60:1e:7a brd ff:ff:ff:ff:ff:ff
  4. inet 10.0.1.20/24 brd 10.0.1.255 scope global eno16777736
  5. valid_lft forever preferred_lft forever
  6. inet6 fe80::20c:29ff:fe60:1e7a/64 scope link
  7. valid_lft forever preferred_lft forever
ip address flush – flush protocol addresses
ip  addr  flush  dev  IFACE
  1. ]# ip addr add 10.10.10.10/8 dev eth1 label eth1:0
  2. ]# ip addr add 172.16.1.100/16 dev eth1 label eth1:1
  3. ]# ip addr show eth1
  4. 3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
  5. link/ether 00:0c:29:ae:e4:e2 brd ff:ff:ff:ff:ff:ff
  6. inet 192.168.1.100/24 brd 192.168.1.255 scope global eth1
  7. inet 10.10.10.10/8 scope global eth1:0
  8. inet 172.16.1.100/16 scope global eth1:1

  9. ]# ip addr flush dev eth1 ]# ip addr show eth1 3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:ae:e4:e2 brd ff:ff:ff:ff:ff:ff
ip route – routing table management
ip route add – add new route
ip route change – change route
ip route replace – change or add new one
ip  route   add  TYPE PREFIX  via GW  [dev  IFACE]  [src SOURCE_IP]
  1. ]# ip route add 172.16.0.0/16 via 10.0.1.2 dev eth0 src 10.0.1.6
  2. ]# ip route show
  3. 10.0.1.0/24 dev eth0 proto kernel scope link src 10.0.1.6
  4. 192.168.1.0/24 dev eth1 proto kernel scope link src 192.168.1.10
  5. 172.16.0.0/16 via 10.0.1.2 dev eth0 src 10.0.1.6
  6. default via 10.0.1.2 dev eth0
  1. ]# ip route add default via 10.0.1.2 dev eth0
  2. ]# ip route show
  3. 10.0.1.0/24 dev eth0 proto kernel scope link src 10.0.1.6
  4. 192.168.1.0/24 dev eth1 proto kernel scope link src 192.168.1.10
  5. 172.16.0.0/16 via 10.0.1.2 dev eth0 src 10.0.1.6
  6. default via 10.0.1.2 dev eth0
         ip route delete – delete route
 ip  route  del  TYPE PRIFIX 
  1. ]# ip route del 172.16.0.0/16
  2. ]# ip route del default
  3. ]# ip route show
  4. 10.0.1.0/24 dev eth0 proto kernel scope link src 10.0.1.6
  5. 192.168.1.0/24 dev eth1 proto kernel scope link src 192.168.1.10
ip route show – list routes
TYPE PRIFIX  
ip route get – get a single route
ip  route  get  TYPE PRIFIX
  1. ]# ip route get 192.168.1.0/24
  2. broadcast 192.168.1.0 dev eth1 src 192.168.1.10
  3. cache <local,brd> mtu 1500 advmss 1460 hoplimit 64
ss命令:
ss  [options]  [ FILTER ]
选项:
-t:TCP协议的相关连接
-u:UDP相关的连接
-w:raw socket相关的连接
-l:监听状态的连接
-a:所有状态的连接
-n:数字格式
-p:相关的程序及其PID
-e:扩展格式信息
-m:内存用量
-o:计时器信息
FILTER := [ state TCP-STATE ]  [ EXPRESSION ]
TCP的常见状态:
TCP FSM:
LISTEN:监听
ESTABLISEHD:建立的连接
FIN_WAIT_1:
FIN_WAIT_2:
SYN_SENT:
SYN_RECV:
CLOSED:
EXPRESSION:
dport = 
sport = 
示例:'( dport = :22 or sport = :22)’
~]# ss   -tan    ‘(  dport = :22 or sport = :22  )’
~]# ss  -tan  state  ESTABLISHED

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

(0)
N24_ViCiN24_ViCi
上一篇 2016-12-04
下一篇 2016-12-04

相关推荐

  • 马哥教育21期网络班—第13周课程+练习—-samba和vsftp-pam

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

    Linux干货 2016-10-24
  • linux常见文件管理类命令

    1、文件管理类命令主要有mkdir、rmdir、cp、mv、rm等 mkdir:make directory创建文件夹 -p:自动按需创建父目录 -v:显示创建过程 -m:创建时给定文件夹权限 创建层级文件夹时,需保证上一级目录存在,否则会报错,例如   创建层级文件夹时,可以加上-p选项,递归创建不存在的上级目录,例如   rmdir:删除文件夹 -p:删…

    2017-12-10
  • RPM与YUM安装工具介绍与初步使用、编译apache2

      RPM可以对程序 进行安装、卸载、查询、校验和维护     rpm(raedhat package mananger),一以种数据库记录的方式将需要的软件安装到linux系统的一种机制。     RPM最大的特点是将要安装的软件先编译过,并且打包成为RPM机制的安装包,通过包…

    Linux干货 2016-06-01
  • 学习笔记–权限管理

    文件系统的权限管理 1、Linux系统下每个目录或文件的权限对象主要分为:属主(u)、属组(g)、其他用户(o),针对每类访问对象都定义了三种权限:读(r)、写(w)、执行(x),这三种权限针对目录和文件的作用各不相同,以下将做详细说明: 对于文件来说: 读(r)权限:可以使用文本查看类工具读取文件内容 写(w)权限:可以修改文件内容,但不能删除文件本身 执…

    Linux干货 2016-08-05
  • 第十八周

    “1、为LNMP架构添加memcached支持,并完成对缓存效果的测试报告; 架构(3台centos7) nginx与php 192.168.1.108    nginx,php-fpm,php-mysql php-pecl-memcache mysql         192…

    2017-08-21
  • iptables

    练习:基于状态放行telnet, ftp, ssh, http, samba, icmp等服务 (1) 对本机的ping请求每分钟不得超出20个 (2) 每客户端对本机的ssh的并发连接数不得超过3个 (3) 本机的telnet服务仅允许工作时间内访问 [root@node1 ~]# vim iptables.sh iptabl…

    Linux干货 2016-10-22

评论列表(1条)

  • 马哥教育
    马哥教育 2016-12-14 15:45

    博客完成的非常好,有图有真相,有实验结果。加油!