linux包之iproute之ip命令
[root@localhost ~]# rpm -qf /sbin/ip
iproute-2.6.32-31.el6.x86_64
ip 是个命令, ip 命令的功能很多!基本上它整合了 ifconfig 与 route 这两个命令
ip - show / manipulate routing, devices, policy routing and tunnels
ip [ OPTIONS ] OBJECT { COMMAND | help }
OBJECT := { link | addr | addrlabel | route | rule | neigh | tunnel |
maddr | mroute | monitor }
OPTIONS := { -V[ersion] | -s[tatistics] | -r[esolve] | -f[amily] { inet
| inet6 | ipx | dnet | link } | -o[neline] }
[root@ipt ~]# ip addr help
[root@ipt ~]# ip link help
[root@localhost ~]# ip link
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 00:0c:29:75:34:a5 brd ff:ff:ff:ff:ff:ff
ip link
ip link 可以设定与设备 (device) 有关的相关设定,包括 MTU 以及该网络设备的 MAC 等等,当然也可以启动 (up) 或关闭 (down) 某个网络设备。
ip link set [device] [动作与参数] device 指的是 eth0, eth1 等等设备代号
up|down :启动 (up) 或关闭 (down) 某个设备,其他参数使用预设的以太网参数;
address :如果这个设备可以更改 MAC ,用这个参数修改;
name :给予这个设备一个特殊的名字;
mtu :设置最大传输单元。
[root@linux ~]# ip link set eth0 up
# 启动eth0这个设备;
[root@linux ~]# ip link set eth0 down
# 关闭eth0这个设备;
[root@linux ~]# ip link set eth0 mtu 1000
# 更改 MTU为1000 bytes,单位就是 bytes 。
ip link set eth0 address aa:aa:aa:aa:aa:aa
[root@localhost ~]# ip -s link
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
RX: bytes packets errors dropped overrun mcast
108016 473 0 0 0 0
TX: bytes packets errors dropped carrier collsns
108016 473 0 0 0 0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:75:34:a5 brd ff:ff:ff:ff:ff:ff
RX: bytes packets errors dropped overrun mcast
23016263 27785 0 0 0 0
TX: bytes packets errors dropped carrier collsns
2402975 17084 0 0 0 0
[root@localhost ~]# ip addr
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
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:75:34:a5 brd ff:ff:ff:ff:ff:ff
inet 192.168.2.128/24 brd 192.168.2.255 scope global eth0
inet6 fe80::20c:29ff:fe75:34a5/64 scope link
valid_lft forever preferred_lft forever
ip addr
如果说 ip link 是与 OSI 七层模型的第二层数据链路层有关的话,那么 ip address (ip addr) 就是与第三层网络层有关的了。主要是在设定与 IP 有关的各项参数,包括 netmask, broadcast 等等。
ip address [add|del] [IP参数] [dev 设备名] [相关参数]
IP 参数 :主要就是网域的设定,例如 192.168.100.100/24 之类的设定
相关参数如下所示:
broadcast:设定广播位址,如果设定值是 + 表示让系统自动计算;
label :该设备的别名,例如eth0:0;
scope :这个设备的领域,通常是以下几个大类:
global :允许来自所有来源的连接;
site :仅支持IPv6 ,仅允许本主机的连接;
link :仅允许本设备自我连接;
host :仅允许本主机内部的连接;
所以当然是使用 global 了。预设也是 global !
ip addr add 192.168.50.50/24 dev eth1
ip addr del 192.168.50.50/24 dev eth1
[root@localhost ~]# ip addrlabel
prefix ::1/128 label 0
prefix ::/96 label 3
prefix ::ffff:0.0.0.0/96 label 4
prefix 2001::/32 label 6
prefix 2001:10::/28 label 7
prefix 2002::/16 label 2
prefix fc00::/7 label 5
prefix ::/0 label 1
[root@localhost ~]# ip rule
0: from all lookup local
32766: from all lookup main
32767: from all lookup default
使用ip命令的neigh或者neighbour选项,你可以查看接入你所在的局域网的设备的MAC地址。
[root@localhost ~]# ip neigh
192.168.2.190 dev eth0 lladdr 6c:fd:b9:3b:57:ff REACHABLE
192.168.2.2 dev eth0 lladdr 50:46:5d:b9:cd:68 REACHABLE
[root@localhost ~]# ip -s neigh
192.168.2.190 dev eth0 lladdr 6c:fd:b9:3b:57:ff ref 3 used 58/0/2 REACHABLE
192.168.2.2 dev eth0 lladdr 50:46:5d:b9:cd:68 ref 120 used 102/102/82 STALE
[root@localhost ~]# ip route
192.168.50.0/24 dev eth1 proto kernel scope link src 192.168.50.50
192.168.2.0/24 dev eth1 proto kernel scope link src 192.168.2.131 metric 1
default via 192.168.2.2 dev eth1 proto static
ip route
proto:此路由的路由协定,主要有 redirect, kernel, boot, static, ra 等, 其中 kernel 指的是直接由核心判断自动设定。
scope:路由的范围,主要是 link ,是与本设备有关的直接连接。
ip route add 192.168.5.0/24 dev eth0 直连网段
ip route add 192.168.10.0/24 via 192.168.5.100 dev eth0 非直连网段
linux包之iproute之ip命令的更多相关文章
- linux包之iproute之ss命令
概述 [root@localhost ~]# rpm -qa|grep iprouteiproute-2.6.32-31.el6.x86_64 当服务器的socket连接数量变得非常大时,无论是使用n ...
- linux(Ubuntu/Centos) iproute 路由IP地址等命令集合,查看端口链接
原 linux(Ubuntu/Centos) iproute 路由IP地址等命令集合,查看端口链接 2017年03月20日 16:55:57 风来了- 阅读数:2291 标签: centoslinux ...
- Linux 基础教程 27-ss和ip命令
什么是netstat 在Linux系统中输入 man netstat,显示的结果如下所示: netstat - Print network connections, routing table ...
- linux包之procps之sysctl命令
概述 [root@localhost ~]# rpm -qf /sbin/sysctlprocps-3.2.8-25.el6.x86_64 我们常常在 Linux 的 /proc/sys 目录下,手动 ...
- #linux包之tcpdump之tcpdump命令
概述 man tcpdump 已阅 yum install tcpdump Downloading Packages:(1/2): libpcap-1.4.0-1.20130826git2dbcaa1 ...
- #linux包之lsof之lsof命令
2015/3/18查漏补缺,反复练习命令,有不明白或疑问的地方直接看man手册页,英文解释的比较清楚 man lsof 已阅 概述 [root@localhost ~]# rpm -qa|grep l ...
- Linux下的设置静态IP命令详解
网络配置的配置文件在/etc/sysconfig/network-scripts/下,文件名前缀为ifcfg-后面跟的就是网卡的名称,可以通过双TAB键查看然后编辑,也可以使用ifconfig查看,也 ...
- linux包之nc之nc命令
nc-1.84-22.el6.x86_64不用系统上提供的nc版本会有所不同,其提供的参数使用方法也略有差异 nc -v -w 1 192.168.2.10 -z 1-65535|grep succe ...
- linux包之gdb之gdb命令与core文件产生
gdb-7.2-64.el6_5.2.x86_64/usr/bin/gcore/usr/bin/gdb/usr/bin/gdb-add-index/usr/bin/gdbtui/usr/bin/gst ...
随机推荐
- FR #1题解
A. 建图跑最小费用最大流.分类讨论每种情况如何连边,费用怎么定. #include<iostream> #include<cstdio> #include<cstrin ...
- Sheet can not be presented because the view is not in a window的解决办法,和window的简单使用
Sheet can not be presented because the view is not in a window,顺便在stackoverflow上找了答案,希望能给大家带来帮助,在此感谢 ...
- 11、C#基础整理(特殊集合和哈希表)
特殊集合:队列.栈 一.栈Stack类:先进后出,没有索引 Stack ss = new Stack(); 1.增加数据:push :将元素推入集合 ss.Push(); ss.Push(); ss. ...
- python学习札记(1)
首先给大家推荐一个很好的python入门网站,感觉比<python基础>之类的书更容易懂,廖雪峰小站,希望有学习资源同学们也能多多交流.下面是今天所学: 下面总结一些非常有特色的函数及其应 ...
- magento和discuz(ucenter)整合集成开发思路
discuz自带ucenter,主要就是用于和其他程序的通信.我们可以下载discuz的ucenter开发手册进行magento和discuz的集成.里面有一些ucenter的一些接口函数和参数说明, ...
- 听VOA还不如学这些 (转自知乎恶魔奶爸)
该专栏文章网址 http://zhuanlan.zhihu.com/aisapo/19634180 鉴于知乎无法插图片和音频,所以有了这篇教程集合,大家看这个就足够了其实 每次一学英语,材料无非就是V ...
- nethogs 实时查看进程使用流量情况。
源码编译安装. 下载地址:http://sourceforge.net/projects/nethogs/?source=directory 下载了 tar 解压. make && m ...
- Linux下解决“shutdown: command not found"问题
今天关机时,使用shutdown来执行此操作,但出现了一个"bash:shutdown:command not found"错误提示.这让我很困惑,这个命令在系统中是肯定存在的,但 ...
- gulp 制作雪碧图
雪碧图:sprite 是把多张图片拼到一张图中,提升性能的一种做法.把合并的图片一次性加载到内存中,需要时只渲染一部分. 我们选择gulp.spritesmith插件. 使用gulp时首先要在指定的任 ...
- 转:db2 iptables相关用法(2)
Centos 6 iptables 配置 Ben 2011/12/24 [root@localhost ben.liu]# service iptables status Table: filter ...