当前位置:网站首页>"IP" command to configure network interface
"IP" command to configure network interface
2022-08-09 04:18:00 【yuyuyuliang00】
ipcommand is a new network command line tool,它用于在LInuxOne is allocated in the systemIPaddress to a network interface or configuration/Update useful network variables.它是iproute软件包的组成部分,And provides several network management tasks,Such as turning on or off a network interface,Assign and removeIP地址和路由,管理ARP缓存等.
[[email protected] ~]# dnf whatprovides "ip"
Last metadata expiration check: 2:42:10 ago on Mon 01 Aug 2022 07:45:22 PM CST.
iproute-5.15.0-4.el8.x86_64 : Advanced IP routing and network device configuration tools
Repo : @System
Matched from:
Filename : /usr/sbin/ip
Provide : /sbin/ipipThe command is very similar to the old oneifconfig命令,But thanks to the addition of more features and abilities,It's much more powerful.ifconfigcommand in all modern timesLinuxhas been enabled in the distro and is ip命令替代.然而,ifconfigcommand for the most partlinuxReleases are still available.
注意:Please back up the configuration file before making any changes.
如何配置静态IPaddress network protocol(IPv4)
要在Linux中配置静态IP地址,You need to update or edit the network configuration file to assign a staticIPaddress to the system.You must be the one to usesuCommand superuser from terminal or command prompt.
对于RHEL/CentOS/Fedora和Rocky Linux/AlmaLinux
Open and edit the network configuration file with an editor.例如,分配IP地址给enp3s0接口.
[[email protected] ~]# vim /etc/sysconfig/network-scripts/ifcfg-enp3s0输出结果:
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=enp3s0
UUID=aed3f17e-747c-4a13-b421-407bb0a57f69
DEVICE=enp3s0
IPADDR=192.168.3.30
PREFIX=24
ONBOOT=yesAfter setting the configuration,重启网络服务.
[[email protected] network-scripts]# systemctl restart NetworkManager.service1、如何分配一个IPaddress to a specific port
The following commands will be used
[[email protected] ~]# ip addr add 192.168.3.31 dev enp3s0to assign one immediatelyIPaddress to a specific interface(enp3s0).
[[email protected] ~]# ip addr show enp3s0
2: enp3s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether c4:00:ad:54:a3:23 brd ff:ff:ff:ff:ff:ff
inet 192.168.3.30/24 brd 192.168.3.255 scope global noprefixroute enp3s0
valid_lft forever preferred_lft forever
inet 192.168.3.31/32 scope global enp3s0
valid_lft forever preferred_lft forever
inet6 fe80::53ff:e021:58e4:1629/64 scope link noprefixroute
valid_lft forever preferred_lft forever2、如何检测IP地址
To get asIP地址、MACAddress information for the NIC interface information,使用以下命令.
[[email protected] ~]# ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp3s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether c4:00:ad:54:a3:23 brd ff:ff:ff:ff:ff:ff
inet 192.168.3.30/24 brd 192.168.3.255 scope global noprefixroute enp3s0
valid_lft forever preferred_lft forever
inet 192.168.3.31/32 scope global enp3s0
valid_lft forever preferred_lft forever
inet6 fe80::53ff:e021:58e4:1629/64 scope link noprefixroute
valid_lft forever preferred_lft forever
...
8: eno1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 00:19:0f:3d:c9:3d brd ff:ff:ff:ff:ff:ff
inet 192.168.50.74/24 brd 192.168.50.255 scope global noprefixroute dynamic eno1
valid_lft 86072sec preferred_lft 86072sec
inet6 fe80::755d:a1a5:8380:e9f9/64 scope link noprefixroute
valid_lft forever preferred_lft forever
...3、How to remove oneIP地址
The following command will start from the specified interface(enp3s0)Remove an allocationIP地址.
[[email protected] ~]# ip addr del 192.168.3.30/24 dev enp3s0
[[email protected] ~]# ip addr show enp3s0
2: enp3s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether c4:00:ad:54:a3:23 brd ff:ff:ff:ff:ff:ff
inet 192.168.3.31/32 scope global enp3s0
valid_lft forever preferred_lft forever
inet6 fe80::53ff:e021:58e4:1629/64 scope link noprefixroute
valid_lft forever preferred_lft forever4、How to enable network interface
接口名称(enp3s0)的"up"The tag will enable a network interface.例如,The following command will activateenp3s0网卡接口.
[[email protected] ~]# ip link set enp3s0 down
[[email protected] ~]# ip addr show enp3s0
2: enp3s0: <BROADCAST,MULTICAST> mtu 1500 qdisc mq state DOWN group default qlen 1000
link/ether c4:00:ad:54:a3:23 brd ff:ff:ff:ff:ff:ff5、How to disable network interface
接口名称(enp3s0)的"down"Flag to disable a network interface.例如,The following commands will disableenp3s0网络接口.
[[email protected] ~]# ip link set enp3s0 up
[[email protected] ~]# ip addr show enp3s0
2: enp3s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether c4:00:ad:54:a3:23 brd ff:ff:ff:ff:ff:ff
inet 192.168.3.30/24 brd 192.168.3.255 scope global noprefixroute enp3s0
valid_lft forever preferred_lft forever
inet6 fe80::53ff:e021:58e4:1629/64 scope link noprefixroute
valid_lft forever preferred_lft forever6、How to detect routes
Enter the following command to detect the routing table information of the system.
[[email protected] ~]# ip route show
default via 192.168.50.1 dev eno1 proto dhcp metric 100
192.168.3.0/24 dev enp3s0 proto kernel scope link src 192.168.3.30 metric 101
192.168.50.0/24 dev eno1 proto kernel scope link src 192.168.50.74 metric 100
192.168.122.0/24 dev virbr0 proto kernel scope link src 192.168.122.17、How to add static routes
Why do you need to add static routes or manual routes,Because that traffic must not go through the default gateway.We need to add static routes so that traffic takes the best path to its destination.
[[email protected] ~]# ip route add 10.30.40.0/24 via 192.168.3.254 dev enp3s0
[[email protected] ~]# ip route show
default via 192.168.50.1 dev eno1 proto dhcp metric 100
10.30.40.0/24 via 192.168.3.254 dev enp3s0
192.168.3.0/24 dev enp3s0 proto kernel scope link src 192.168.3.30 metric 101
192.168.50.0/24 dev eno1 proto kernel scope link src 192.168.50.74 metric 100
192.168.122.0/24 dev virbr0 proto kernel scope link src 192.168.122.18、How to remove static routes
To remove the assigned static route,Just enter the following command.
[[email protected] ~]# ip route del 10.30.40.0/24
[[email protected] ~]# ip route show
default via 192.168.50.1 dev eno1 proto dhcp metric 100
192.168.3.0/24 dev enp3s0 proto kernel scope link src 192.168.3.30 metric 101
192.168.50.0/24 dev eno1 proto kernel scope link src 192.168.50.74 metric 100
192.168.122.0/24 dev virbr0 proto kernel scope link src 192.168.122.19、How to add permanent static route
在系统重启后,All the above routes will be lost.To add permanent static routes,编辑文件/etc/sysocnfig/network-scripts/route-enp3s0.
[[email protected] network-scripts]# cat route-enp3s0
10.30.40.0/24 via 192.168.3.254 dev enp3s0接着,After entering all the details using the command,重启网络服务.
[[email protected] network-scripts]# systemctl restart NetworkManager
[[email protected] network-scripts]# ip route show
default via 192.168.50.1 dev eno1 proto dhcp metric 100
10.30.40.0/24 via 192.168.3.254 dev enp3s0
192.168.3.0/24 dev enp3s0 proto kernel scope link src 192.168.3.30 metric 101
192.168.50.0/24 dev eno1 proto kernel scope link src 192.168.50.74 metric 100
192.168.122.0/24 dev virbr0 proto kernel scope link src 192.168.122.110、How to add default gateway
The default gateway can be specified globally or for an interface-specific configuration file.The advantage of default gateway is if we have multiple network cards in the system.You can immediately add the default gateway with the following command.
[[email protected] network-scripts]# ip route add default via 192.168.3.254
[[email protected] network-scripts]# ip route show
default via 192.168.3.254 dev enp3s0
default via 192.168.50.1 dev eno1 proto dhcp metric 100
10.30.40.0/24 via 192.168.3.254 dev enp3s0
192.168.3.0/24 dev enp3s0 proto kernel scope link src 192.168.3.30 metric 101
192.168.50.0/24 dev eno1 proto kernel scope link src 192.168.50.74 metric 100
192.168.122.0/24 dev virbr0 proto kernel scope link src 192.168.122.111、How to remove the default gateway
The default gateway can be deleted with the following command.
[[email protected] network-scripts]# ip route del default via 192.168.3.254
[[email protected] network-scripts]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.50.1 0.0.0.0 UG 100 0 0 eno1
10.30.40.0 192.168.3.254 255.255.255.0 UG 0 0 0 enp3s0
192.168.3.0 0.0.0.0 255.255.255.0 U 101 0 0 enp3s0
192.168.50.0 0.0.0.0 255.255.255.0 U 100 0 0 eno1
192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0边栏推荐
- 阿里云天池大赛赛题(机器学习)——O2O优惠券预测(完整代码)
- 了解CV和RoboMaster视觉组(五)local-distribution汇聚方法
- 32 Basic Statistics - Hypothesis Testing
- 两种K线形态预示今日伦敦银走向
- 了解CV和RoboMaster视觉组(五)滤波器、观测器和预测方法:自适应滤波器
- A few words about Microsoft's 2022/2023 autumn recruits
- Go常用命令与基础语法
- MKNetworkKit replacing domain name wrong solution
- 查询某时间段获得的积分总积分的大小进行排序
- Query the size of the total points obtained in a certain time period to sort
猜你喜欢

电脑重装系统如何在 Win11查看显卡型号信息

了解CV和RoboMaster视觉组(五)滤波器、观测器和预测方法:卡尔曼滤波器

软件质效领航者 | 优秀案例•国金证券DevOps建设项目
![[Server data recovery] A case of data recovery when the Ext4 file system cannot be mounted and an error is reported after fsck](/img/65/f16bb466967993934719022145f78c.png)
[Server data recovery] A case of data recovery when the Ext4 file system cannot be mounted and an error is reported after fsck

OpenCV相机标定完全指南(有手就行)

机器人工程师入门知识框架(思维导图)

2022年安全员-B证考试练习题及在线模拟考试

LeetCode-从链表中删去总和值为零的连续结点

了解CV和RoboMaster视觉组(五)local-distribution汇聚方法

阿里云天池大赛赛题(机器学习)——天猫用户重复购买预测(完整代码)
随机推荐
『HarmonyOS』Page与AbilitySlice的生命周期
OpenCV相机标定完全指南(有手就行)
数据库指标是怎么个意思
Swift3.0 sets the background color and text color of the status bar
了解CV和RoboMaster视觉组(五)滤波器、观测器和预测方法:卡尔曼滤波器
了解CV和RoboMaster视觉组(五)图像处理中使用的滤波器
数量遗传学遗传力计算2:半同胞和全同胞
2022年安全员-A证特种作业证考试题库及在线模拟考试
记录一次腾讯实习投递经历(一)
【服务器数据恢复】Ext4文件系统fsck后mount不上并报错的数据修复案例
2022年低压电工练习题及模拟考试
MySQL:意向共享锁和意向排它锁 | 死锁 | 锁的优化
【每日一题】761. 特殊的二进制序列
TASSEL软件导入plink格式文件报错
【二叉树】重建二叉树
31 基本统计概念
消失的遗传力--wiki
配置网络接口的“IP“命令
360 评估反馈问题的示范案例
MATLAB | 比生命游戏更自由的生命游戏