当前位置:网站首页>"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/ip
ipThe 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=yes
After setting the configuration,重启网络服务.
[[email protected] network-scripts]# systemctl restart NetworkManager.service
1、如何分配一个IPaddress to a specific port
The following commands will be used
[[email protected] ~]# ip addr add 192.168.3.31 dev enp3s0
to 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 forever
2、如何检测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 forever
4、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:ff
5、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 forever
6、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.1
7、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.1
8、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.1
9、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.1
10、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.1
11、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
边栏推荐
猜你喜欢
随机推荐
“error“: { “root_cause“: [{ “type“: “circuit_breaking_exception“, “reason“: “[parent] D【已解决】
NanoDet代码逐行精读与修改(一)Backbone
遗传力缺失的案例
How to resolve the conflict between LAN segment and WAN segment when Honor router (WS831) is used as wireless relay
松柏集(江风起)
etcd Study Notes - Getting Started
了解CV和RoboMaster视觉组(五)滤波器、观测器和预测方法:维纳滤波器Wiener Filter,LMS
【周赛复盘】力扣第 305 场单周赛
助力To B业务,这类企业端数据值得风控童鞋关注
MySQL:意向共享锁和意向排它锁 | 死锁 | 锁的优化
XJTUSE专业课与实验指南
2分钟,带你走完企业经营分析全流程,更有通用分析框架直接套用
串扰与防护
07.1 Supplements to the class
30 norm
容易混淆的指针知识点
Query the size of the total points obtained in a certain time period to sort
了解CV和RoboMaster视觉组(五)CNN没有不变性?
人类微生物组和缺失遗传力--读论文
If A, B, C, and D process parts, the total number of processed parts is 370. If the number of parts processed by A is 10 more, if the number of parts processed by B is 20 less, if the number of parts