Some common commands for setting network parameters in Linux

齐天大圣
Release: 2020-11-16 11:12:14
Original
2783 people have browsed it

Here are three commands related to network settings:

  • ifconfig: Query and set network card and ip, subnet mask and other parameters (net-tools tool needs to be installed first)

  • ifup, ifdown: Start and shut down the network interface

  • route: View and configure routing information

ifconfig

First look at the ifconfig command

ifconfig [网卡名] [选项] up、down:启动或关闭该网络接口 mtu:设置mtu值 netmask:设置子网掩码 broadcast:设置广播地址
Copy after login

First look at the first example to view all network cards on the system, just enter ifconfig Just use the command without adding any parameters

# ifconfig eth0: flags=4163 mtu 1500 inet 192.168.2.220 netmask 255.255.255.0 broadcast 192.168.2.255 inet6 fe80::1733:cf21:906d:57af prefixlen 64 scopeid 0x20 ether 00:0c:29:84:5b:d0 txqueuelen 1000 (Ethernet) RX packets 9946 bytes 10315936 (9.8 MiB) RX errors 0 dropped 3 overruns 0 frame 0 TX packets 2208 bytes 186213 (181.8 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73 mtu 65536 ……
Copy after login

From the output information of this command, we can get a lot of information, such as network card name, IP address, subnet mask, broadcast address, etc.

Let's continue to look at a few examples

# 修改ip地址 # ifconfig eth0 192.168.1.222
Copy after login

You will find that you only modified the IP address, but the broadcast address will also change accordingly.

# 同时修改ip、子网掩码以及mtu值 ifconfig eth0 192.168.2.222 netmask 255.255.240.0 mtu 1000
Copy after login

Please practice with confidence as soon as possible. In the end, you only need to restart the network and it will be restored to the settings of the previous configuration file

ifup ifdown
Copy after login

When we modify the network configuration file /etc/sysconfig/network-scripts/ After eth0, I want to take effect immediately. Then you need to use

ifdown eth0 ifup eth0
Copy after login

In addition to this method, generally we will also use

/etc/init.d/network restart
Copy after login

to restart all network cards.

route

route This command can view the routing table and can also be used to set routes.

View routing information route [-nee]

  • -n: Do not display the host name, display it directly with IP, which is faster. This option has many commands about the network.

  • -ee: Display more detailed information

# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 172.19.255.253 0.0.0.0 UG 0 0 0 eth0 169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth0 172.19.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
Copy after login
  • Destination : Network address

  • Genmask: Subnet mask, Destination and Genmask form a network

  • Gateway: Gateway address (if displayed is 0.0. 0.0 means that the route is transmitted directly by the local machine, that is, it can be sent directly through the LAN. If the IP address is displayed, it means that the route needs the help of the router (gateway) before it can be sent out.

  • Flag: Flag, the common U indicates that the route is enabled, G indicates that the route needs to transmit data packets through an external host.

The above is the detailed content of Some common commands for setting network parameters in Linux. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!