1024programmer Linux Some common commands for setting network parameters in linux-linux operation and maintenance

Some common commands for setting network parameters in linux-linux operation and maintenance

Here are three commands related to network settings:

  • ifconfig: query, set network card and ip, subnet mask, etc. Parameters (need to install the net-tools tool first)

  • ifup, ifdown: start and close the network interface

  • route: view 、Configure routing information

ifconfig

First look at the ifconfig command

ifconfig [network card name] [options]
 up, down: enable or disable the network interface
 mtu: set the mtu value
 netmask: Set the subnet mask
 broadcast: Set the broadcast address

First look at the first example, to view all network cards on the system, just enter the ifconfig 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
   ...

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 Example

# Modify the ip address
 # ifconfig eth0 192.168.1.222

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

# Modify ip, subnet mask and mtu value at the same time
 ifconfig eth0 192.168.2.222 netmask 255.255.240.0 mtu 1000

Please feel free to practice as soon as possible, and finally you only need to restart the network to restore the previous configuration file settings

ifup ifdown

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

ifdown eth0
 ifup eth0

In addition to this method, we generally use

/etc/init.d/network restart

to restart all network cards.

route

This command can view the routing table, or use to set up routing.

View routing information route [-nee]

  • -n: Do not display the host name, use it directly ip shows that the speed 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
  • Destination: network address

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

  • Gateway: Gateway address (if it is displayed as 0.0.0.0, it means that the route is directly It is transmitted by this 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 a router (gateway) before it can be sent.

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

The above are some common ones in linux For more details about the commands for setting network parameters, please pay attention to other related articles on 1024programmer.com!

This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/some-common-commands-for-setting-network-parameters-in-linux-linux-operation-and-maintenance/

author: admin

Previous article
Next article

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索