10.6 ip:网络配置工具
ip命令是iproute软件包中的一个强大的网络配置工具,用于显示或管理Linux系统的路由、网络设备、策略路由和隧道。
ip命令的参数选项及说明
显示网络设备属性
[root@cs6 ~]# ip link show dev eth1
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:8c:6a:0e brd ff:ff:ff:ff:ff:ff [root@cs6 ~]# ip -s link show dev eth1
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:8c:6a:0e brd ff:ff:ff:ff:ff:ff
RX: bytes packets errors dropped overrun mcast
0 0 0 0 0 0
TX: bytes packets errors dropped carrier collsns
828 12 0 0 0 0
[root@cs6 ~]# ip -s -s link show dev eth1 # 使用两个s显示更详细的属性
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:8c:6a:0e brd ff:ff:ff:ff:ff:ff
RX: bytes packets errors dropped overrun mcast
0 0 0 0 0 0
RX errors: length crc frame fifo missed
0 0 0 0 0
TX: bytes packets errors dropped carrier collsns
828 12 0 0 0 0
TX errors: aborted fifo window heartbeat
0 0 0 0
关闭和激活设备
[root@cs6 ~]# ip link show dev eth1
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:8c:6a:0e brd ff:ff:ff:ff:ff:ff
[root@cs6 ~]# ip link set eth1 down
[root@cs6 ~]# ip link show dev eth1
3: eth1: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast state DOWN qlen 1000
link/ether 00:0c:29:8c:6a:0e brd ff:ff:ff:ff:ff:ff
修改MAC地址
[root@cs6 ~]# ip link show dev eth1
3: eth1: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast state DOWN qlen 1000
link/ether 00:0c:29:8c:6a:0e brd ff:ff:ff:ff:ff:ff
[root@cs6 ~]# ip link set eth1 address 0:0c:29:13:10:11 #<=修改MAC地址
[root@cs6 ~]# ip link show dev eth1
3: eth1: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast state DOWN qlen 1000
link/ether 00:0c:29:13:10:11 brd ff:ff:ff:ff:ff:ff
查看网卡信息
查看网卡信息
[root@cs6 ~]# ip a
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:8c:6a:04 brd ff:ff:ff:ff:ff:ff
inet 10.0.0.100/24 brd 10.0.0.255 scope global eth0
inet6 fe80::20c:29ff:fe8c:6a04/64 scope link
valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast state DOWN qlen 1000
link/ether 00:0c:29:13:10:11 brd ff:ff:ff:ff:ff:ff
inet 172.16.1.100/24 brd 172.16.1.255 scope global eth1
[root@cs6 ~]# ip link
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:8c:6a:04 brd ff:ff:ff:ff:ff:ff
3: eth1: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast state DOWN qlen 1000
link/ether 00:0c:29:13:10:11 brd ff:ff:ff:ff:ff:ff
添加删除IP
添加或删除IP地址
[root@cs6 ~]# ip a show eth1
3: eth1: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast state DOWN qlen 1000
link/ether 00:0c:29:13:10:11 brd ff:ff:ff:ff:ff:ff
inet 172.16.1.100/24 brd 172.16.1.255 scope global eth1
[root@cs6 ~]# ip link set eth1 up
[root@cs6 ~]# ip link show dev eth1
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:13:10:11 brd ff:ff:ff:ff:ff:ff [root@cs6 ~]# ip a add 172.16.1.13/24 dev eth1
# 可以添加多个IP地址,这种称为辅助IP,前面ifconfig 命令创建的为别名称IP.现在采用的高可用软件诶heartbeat 、keepalive都采用了辅助IP
[root@cs6 ~]# ip a show eth1
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:13:10:11 brd ff:ff:ff:ff:ff:ff
inet 172.16.1.100/24 brd 172.16.1.255 scope global eth1
inet 172.16.1.13/24 scope global secondary eth1
inet6 fe80::20c:29ff:fe13:1011/64 scope link
valid_lft forever preferred_lft forever
[root@cs6 ~]# ip a del 172.16.1.100/24 dev eth1 # 删除主IP
[root@cs6 ~]# ip a show eth1
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:13:10:11 brd ff:ff:ff:ff:ff:ff
inet6 fe80::20c:29ff:fe13:1011/64 scope link
valid_lft forever preferred_lft forever
#IP地址全部被删除 [root@cs6 ~]# ip a add 172.16.1.100/24 dev eth1
[root@cs6 ~]# ip a add 172.16.1.13/24 dev eth1
[root@cs6 ~]# ip a del 172.16.1.13/24 dev eth1
[root@cs6 ~]# ip a show eth1
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:13:10:11 brd ff:ff:ff:ff:ff:ff
inet 172.16.1.100/24 scope global eth1
inet6 fe80::20c:29ff:fe13:1011/64 scope link
valid_lft forever preferred_lft forever
小结
删除网卡的主IP地址,同时会删除该网卡的所有IP地址。
删除网卡的辅助IP地址,不会影响该网卡的其他IP地址。
使用ip命令创建别名IP
[root@cs6 ~]# ip a show eth1
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:13:10:11 brd ff:ff:ff:ff:ff:ff
inet 172.16.1.100/24 scope global eth1
inet6 fe80::20c:29ff:fe13:1011/64 scope link
valid_lft forever preferred_lft forever
使用label选项创建别名IP
[root@cs6 ~]# ip a add 10.0.0.29/32 dev eth1 label eth1:1
[root@cs6 ~]# ip a show eth1
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:13:10:11 brd ff:ff:ff:ff:ff:ff
inet 172.16.1.100/24 scope global eth1
inet 10.0.0.29/32 scope global eth1:1
inet6 fe80::20c:29ff:fe13:1011/64 scope link
valid_lft forever preferred_lft forever
[root@cs6 ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:8C:6A:04
inet addr:10.0.0.100 Bcast:10.0.0.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe8c:6a04/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:2876 errors:0 dropped:0 overruns:0 frame:0
TX packets:1835 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:266051 (259.8 KiB) TX bytes:198053 (193.4 KiB) eth1 Link encap:Ethernet HWaddr 00:0C:29:13:10:11
inet addr:172.16.1.100 Bcast:0.0.0.0 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe13:1011/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:18 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 b) TX bytes:1296 (1.2 KiB) eth1:1 Link encap:Ethernet HWaddr 00:0C:29:13:10:11
inet addr:10.0.0.29 Bcast:0.0.0.0 Mask:255.255.255.255
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
备注:使用ifconfig命令创建的别名IP,ip命令能够查询到;相反,通过ip命今创建的辅助IP,ifconfig命令则查询不了,除非使用ip命令的label功能创建别名IP。
查看路由表
[root@cs6 ~]# ip route
10.0.0.0/24 dev eth0 proto kernel scope link src 10.0.0.100
172.16.1.0/24 dev eth1 proto kernel scope link src 172.16.1.100
169.254.0.0/16 dev eth0 scope link metric 1002
default via 10.0.0.2 dev eth0
[root@cs6 ~]# ip route|column -t
10.0.0.0/24 dev eth0 proto kernel scope link src 10.0.0.100
172.16.1.0/24 dev eth1 proto kernel scope link src 172.16.1.100
169.254.0.0/16 dev eth0 scope link metric 1002
default via 10.0.0.2 dev eth0
#<==使用column命令格式化,选项-t,默认根据空格分隔判断输入行的到数来创建一个表。
[root@cs6 ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
10.0.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
172.16.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1
169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth0
0.0.0.0 10.0.0.2 0.0.0.0 UG 0 0 0 eth0
添加静态路由
[root@cs6 ~]# ip route add 10.1.0.0/24 via 10.0.0.253 dev eth0
[root@cs6 ~]# ip route |column -t
10.0.0.0/24 dev eth0 proto kernel scope link src 10.0.0.100
172.16.1.0/24 dev eth1 proto kernel scope link src 172.16.1.100
10.1.0.0/24 via 10.0.0.253 dev eth0
169.254.0.0/16 dev eth0 scope link metric 1002
default via 10.0.0.2 dev eth0
查看ARP缓存
查看ARP缓存
[root@cs6 ~]# ip neighbour
10.0.0.1 dev eth0 lladdr 00:50:56:c0:00:08 REACHABLE
10.0.0.2 dev eth0 lladdr 00:50:56:f4:fb:52 STALE
10.0.0.99 dev eth0 FAILED 添加或删除静态ARP项
[root@cs6 ~]# ip neighbour add 192.168.1.100 lladdr 00:50:56:f4:fb:55 dev eth0
[root@cs6 ~]# ip neighbour
192.168.1.100 dev eth0 lladdr 00:50:56:f4:fb:55 PERMANENT
10.0.0.1 dev eth0 lladdr 00:50:56:c0:00:08 REACHABLE
10.0.0.99 dev eth0 FAILED
10.0.0.2 dev eth0 lladdr 00:50:56:f4:fb:52 STALE [root@cs6 ~]# ip neighbour del 192.168.1.100 dev eth0
[root@cs6 ~]# ip neighbour
192.168.1.100 dev eth0 FAILED
10.0.0.1 dev eth0 lladdr 00:50:56:c0:00:08 REACHABLE
10.0.0.99 dev eth0 FAILED
10.0.0.2 dev eth0 lladdr 00:50:56:f4:fb:52 STALE
10.6 ip:网络配置工具的更多相关文章
- 网络配置工具iproute2和net-tools的基本原理和基本使用方法
这是网络程序设计课程的第一次作业的博客,由于还是小白,分享的内容都是比较基础的东西,希望看到的各位同学可以提出指导意见,必将虚心听取. 这次分享的内容是网络配置工具iproute2和net-tools ...
- CentOS 7网络配置工具
CentOS 7网络配置工具 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.网卡命名机制 CentOS 6之前,网络接口使用连续号码命名:eth0.eth1等,当增加或删除网卡 ...
- linux 无线网络配置工具wpa_supplicant与wireless-tools
4.a. 介绍目前您可以使用我们提供的wireless-tools 或wpa_supplicant工具来配置无线网络.请记住重要的一点是,您对无线网络的配置是全局性的,而非针对具体的接口.wpa_su ...
- Ubuntu 16.04通过网络配置工具NetworkManager设置IP、网关、DNS和查看IP、网关、DNS
说明: 1.NetworkManager工具是Ubuntu桌面版的GUI设置工具. 2.这个工具推荐直接在GUI上操作,不建议用命令行进行管理,比如Wifi这些配置等. 3.当然,这个工具能带有命令行 ...
- IP网络性能测试工具——Renix Perf
一.Renix Perf 基于软件的网络及应用服务性能测试工具 · 双臂测试 · 单臂测试 通过测试端点产生网络流量对网络性能进行测量 · TCP.UDP.PING · 语音.视频.HTTP.FTP. ...
- ubuntn 虚拟机NAT 静态IP 网络配置
在虚拟机安装ubuntu12.04自动获取IP 一切都没有问题 ssh连接也正常.关机重启后郁闷的发现网络已经不通了,于是开始了以下的摸索. 1.配置静态IP 网关: ip段: 命令: Vim /et ...
- Xshell 连接虚拟机OS Linux 设置静态ip ,网络配置中无VmWare8 的解决办法
前序:最近开始研究Hadoop平台的搭建,故在本机上安装了VMware workstation pro,并创建了Linux虚拟机(centos系统),为了方便本机和虚拟机间的切换,准备使用Xshell ...
- CentOS 7 网络配置工具
之前在CentOS 6下编辑网卡,直接使用setup工具就可以了. 但在新版的CentOS 7里,setuptool已经没有网络编辑组件了,取而代之的是NetworkManager Text User ...
- Linux修改IP网络配置
文件路径:/etc/sysconfig/networe-scripts/ifcfg-eth0 BOOTPROTO="static" IPADDR=IP地址 NETMASK=掩码 G ...
随机推荐
- es的分布式架构原理能说一下么(es是如何实现分布式的啊)?
在搜索这块,lucene是最流行的搜索库.几年前业内一般都问,你了解lucene吗?你知道倒排索引的原理吗?现在早已经out了,因为现在很多项目都是直接用基于lucene的分布式搜索引擎--elast ...
- JavaScript 中对象解构时指定默认值
待解构字段为原始值 正常情况下, const obj = { a: 1, b: 2, }; const { a, b } = obj; console.log(a, b); // 1 2 当被解构字段 ...
- 前后端分离中的无痛刷新token机制
今天我们来说一说前后端分离中的无痛刷新token机制 博主先来分享一波福利,最近挖到的宝藏,刚开始学Java的同学看 https://www.bilibili.com/video/BV1Rx41187 ...
- Weekly Contest 139
1071. Greatest Common Divisor of Strings For strings S and T, we say "T divides S" if and ...
- 轮子:DateUtil.java
日期工具类 import java.text.SimpleDateFormat; import java.util.Date; public class DateUtil { public stati ...
- 【接口设计】用户积分排行榜功能-Redis实现
一.排行榜功能简介 排行榜功能是一个很普遍的需求.使用 Redis 中有序集合(SortedSet)的特性来实现排行榜是又好又快的选择. 一般排行榜都是有实效性的,比如交通数据流中的路口/路段的车流量 ...
- hdu4932 小贪心
题意: 给了一些处在x轴上的点,要求我们用长度相等的线段覆盖所有点,线段和线段之间不能重叠,问线段最长可以使多长. 思路: 一开始一直在想二分,哎!感觉这个题目很容易就往二分上去 ...
- 11.PHP与MySQL
PHP与MySQL 首先是PHPStorm设置创建SQL的教程,找到了一个写的不错的,在这里:http://blog.csdn.net/knight_quan/article/details/5198 ...
- c# 通过 p/invoke 使用 c的加密程序 参数传递问题
最近项目中使用需要上位机和下位机通过rs232通信,涉及到通讯加密问题, 硬件那边主要是pcb layout的,于是我就把加密的活拦了过来,锻炼锻炼 首先说明问题: 在c中,加密解密都测试通过,然后在 ...
- 简化mapstruct代码: mapstruct-spring-plus
mapstruct MapStruct 是一个属性映射工具,只需要定义一个 Mapper 接口,MapStruct 就会自动实现这个映射接口,避免了复杂繁琐的映射实现.MapStruct官网地址: h ...