Set basic network parameters in Linux

Source: Internet
Author: User
Article title: set basic network parameters in Linux. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

All of the following operations are implemented in the command line mode on the plain text interface. these operations can be implemented through the desktop or X-Window mode, but generally, the Linux operating system running as a server does not install X-Window. Therefore, using the command line is also a basic skill for using the Linux operating system. In addition, most of the operations mentioned in this article must be performed under the root account.

Basic network settings:

First, describe the content contained in the basic network settings, including the Nic parameters, including IP address, subnet mask, Gateway, DNS settings, and host name settings.

There are two main ways to set network interface parameters. one is to temporarily change the network interface parameters. after the system restarts, all the changes made before will disappear, the other method is to change the network interface parameters permanently. the reason for this is that the changes do not expire after the system is shut down or restarted, however, you can change the network interface parameters in the preceding two ways.

The following two methods are described separately.

The first method can be implemented through the command ifconfig. the prototype of the command is # ifconfig ethx. The x in ethx represents the Nic ID to be changed, which is generally 0. This command can temporarily change the IP address of the NIC. you do not need to restart the NIC to make the change take effect. Similarly, you can use the # ifconfig ethx netmask command to temporarily change the Nic subnet mask.

Note: in the command prototype, it indicates that the actual IP address needs to be changed to the actual IP address. Similarly, it indicates the actual subnet mask that needs to be entered during actual input. This type of format will be used in subsequent examples. For example, to set the IP address of the first network adapter to 192.168.0.1 subnet mask to 255.255.255.0, the actual command is # ifconfig eth0 192.168.0.1 netmask 255.255.255.0.

The second method is to use the netconfig command to permanently change the network interface parameters. Run the command # netconfig. in the displayed dialog box, select Yes to display the setting interface. If the current system is connected to a network with a DHCP server and the current system needs to use the IP address specified by the DHCP server, click a space in the use dynamic IP configuration (BOOTIP/DHCP, use the Tab key to move the cursor to OK and press enter. If the system needs to manually specify the network interface parameters, you can move the cursor to IP address, Netmask, Default Gateway (IP), and Primary nameserver in sequence, set four parameters, including the IP address, subnet mask, default gateway, and preferred DNS server of the network adapter. after entering the parameters, click OK.

After setting, you need to restart the NIC to make the above settings take effect. start the NIC using the following two commands: ifdown and ifup. The specific commands are # ifdown eth0 and # ifup eth0 respectively. after The NIC is restarted, run the ifconfig command to check whether the settings take effect.

Another way to do this is to change the Nic operating parameters by changing the/etc/sysconfig/network-script/ifcfg-eth0 file. Eth0 indicates that the first network card of the system is to be changed. if other network cards of the system are changed, select the file to be changed.

Open the file with the command # vi/etc/sysconfig/network-script/ifcfg-eth0 and press the key to enter edit mode. The following explains the meaning of the items in the file for ease of change.

DEVICE = eth0 indicates the ID of the network adapter to be changed. the first network adapter is eth0, the second is eth1, and so on.

ONBOOT = yes indicates whether to enable this setting when the system starts. generally, it is set to yes, that is, it is enabled when the system starts.

BOOTPROTO = static this item shows how the nic ip address is obtained. if the IP address is automatically obtained by the DHCP server, the value of this item should be dynamic, and the following three items do not exist; if the IP address is set manually, the value of this item is static and there are three items.

IPADDR = 192.168.0.1 this item is the IP address of the network adapter set manually. when BOOTPROTO = dynamic, this item does not exist.

NETMASK = 255.255.255.0 this item is the subnet mask of the manually set Nic, and must match the IP address correctly. when BOOTPROTO = dynamic, this item does not exist.

GATEWAY = 192.168.0.254 this item is the default GATEWAY of the manually set Nic. when BOOTPROTO = dynamic, this item does not exist.

After the changes are completed, press ESC on the keyboard to exit the vi editing mode. enter wq on the keyboard and press enter to save the changes to the file and exit the vi editor. After you use this method to change the network interface parameters, you also need to use the ifdown and ifup commands to make the settings take effect.

Change host name:

To change the host name, you must modify the following two files:/etc/sysconfig/network and/etc/hosts. use vi/etc/sysconfig/network to open the network file, change the value of the HOSTNAME item to the host name you want to change. save and exit, use vi/etc/hosts to open the hosts file, and add <你的linux主机ip> If you want to change the host name, note that the IP address and host name must be separated by spaces, and add the host name you want to change to before the localhost. localdomain line of 127.0.0.1 localhost. localdomain localhost in the original file. Note: there must be at least one space between the host name and localhost. localdomain you want to modify. Save and exit after editing. Note that the three hostnames in the two files must be consistent.

Note: it is not recommended to change the host name after system installation is complete, because this may cause the system to start the Sendmail service abnormally slowly when the system starts.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.