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 ...
随机推荐
- OO_Unit4暨学期总结
OO_Unit4暨学期总结 一.本单元架构设计 1.1 第13次作业架构设计 就我个人而言,这次作业应该是本单元难度最大的一次作业,原因在于陡然转向UML后,对UML各个元素的关系理解需要先下一番功夫 ...
- Linux 以非root用户安装zsh&配置on my zsh
此文章参考以下三篇文章,如有侵权请联系 Linux非root用户安装zsh, 并用oh-my-zsh进行配置 在没有sudo权限的Linux服务器下安装oh-my-zsh 不使用root权限安装zsh ...
- Leedcode算法专题训练(栈和队列)
1. 用栈实现队列 232. Implement Queue using Stacks (Easy) Leetcode / 力扣 class MyQueue { Stack<Integer> ...
- python基础(补充):递归的深度
我们在正经人谁用递归呀一节中,简单的讨论了python中的递归 相信用过python递归的朋友可能都碰到过: RecursionError: maximum recursion depth excee ...
- [Skill]从零掌握80%的业务查询SQL语句
前言 本篇文章的主要目的是帮助初学者快速入门SQL查询,从而解决实际业务中80%的SQL查询问题. 本文主要框架如下: 上篇:介绍SQL的语法顺序和执行顺序 中篇:介绍条件子句.分组查询和排序的细节 ...
- (十六)VMware Harbor 复制镜像
Step 1: 点击复制镜像后 Step 2: 填写复制镜像信息 Step 3:在sx628下,会多出一个镜像
- Cube painting UVA - 253
We have a machine for painting cubes. It is supplied with three different colors: blue, red and gre ...
- spring boot最新版使用几个坑解决
<groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent ...
- 模拟退火算法(1)Python 实现
1.模拟退火算法 模拟退火算法借鉴了统计物理学的思想,是一种简单.通用的启发式优化算法,并在理论上具有概率性全局优化性能,因而在科研和工程中得到了广泛的应用. 退火是金属从熔融状态缓慢冷却.最终达到能 ...
- OO第四单元总结与课程总结
OO第四单元总结与课程总结 第四单元作业架构设计 总体分析:本单元作业的需求集中于对UML类图进行查询.对于查询操作来说自然的想法是提前预见到需要查询的内容,在一开始就采用适当的数据结构将必要的信息进 ...