CentOS (9) for Linux-network environment configuration for Linux

Source: Internet
Author: User

This article mainly records the network environment configuration in Linux. Linux and Unix are the world of networks. Therefore, how to configure network environment variables in Linux is crucial, here we will provide three methods for configuring the network environment in Linux!

Before configuring the network environment, add several common Linux commands:

History command: Lists All commands previously entered. parameters such as history 5 are often followed by the five most recently used commands.

[Root @ xiaoluo ~] # History 5
1064 ifconfig eth0 172.25.215.31
1065 ifconfig
1066 ping 172.25.215.25
1067 history
1068 history 5

!Command: run the command with the specified serial number, for example :! 1065, the command ifconfig corresponding to 1065 will be executed (this serial number corresponds to the serial number of the previously entered command)
[Root @ xiaoluo ~] #! 1065
Ifconfig
Eth0 Link encap: Ethernet HWaddr 00: 0C: 29: B2: 10: 6A
Inet addr: 172.25.215.31 Bcast: 172.25.215.255 Mask: 255.255.255.0
Inet6 addr: fe80: 20c: 29ff: feb2: 106a/64 Scope: Link
Up broadcast running multicast mtu: 1500 Metric: 1
RX packets: 18162 errors: 0 dropped: 0 overruns: 0 frame: 0
TX packets: 5625 errors: 0 dropped: 0 overruns: 0 carrier: 0
Collisions: 0 FIG: 1000
RX bytes: 2458244 (2.3 MiB) TX bytes: 508443 (496.5 KiB)

Lo Link encap: Local Loopback
Inet addr: 127.0.0.1 Mask: 255.0.0.0
Inet6 addr: 1/128 Scope: Host
Up loopback running mtu: 16436 Metric: 1
RX packets: 2755 errors: 0 dropped: 0 overruns: 0 frame: 0
TX packets: 2755 errors: 0 dropped: 0 overruns: 0 carrier: 0
Collisions: 0 txqueuelen: 0
RX bytes: 226350 (221.0 KiB) TX bytes: 226350 (221.0 KiB)

Virbr0 Link encap: Ethernet HWaddr 52: 54: 00: 0A: 92: EB
Inet addr: 192.168.122.1 Bcast: 192.168.122.255 Mask: 255.255.255.0
Up broadcast running multicast mtu: 1500 Metric: 1
RX packets: 0 errors: 0 dropped: 0 overruns: 0 frame: 0
TX packets: 308 errors: 0 dropped: 0 overruns: 0 carrier: 0
Collisions: 0 txqueuelen: 0
RX bytes: 0 (0.0 B) TX bytes: 83017 (81.0 KiB)

Virbr0-nic Link encap: Ethernet HWaddr 52: 54: 00: 0A: 92: EB
Inet6 addr: fe80: 5054: ff: fe0a: 92eb/64 Scope: Link
Up broadcast running multicast mtu: 1500 Metric: 1
RX packets: 0 errors: 0 dropped: 0 overruns: 0 frame: 0
TX packets: 0 errors: 0 dropped: 5998 overruns: 0 carrier: 0
Collisions: 0 FIG: 500
RX bytes: 0 (0.0 B) TX bytes: 0 (0.0 B)

The following describes how to configure the network environment in three Linux systems:

1. Log On As root and enterSetupCommand, such:

[root@xiaoluo ~]# setup

The system configuration page is displayed:

You can select the corresponding configuration through the up and down arrows. Select network configuration here, and press enter to go to the network configuration page:

Select the device configuration here and enter the device selection page.

Here we select the etho Nic. We will set the network environment for it and click "enter:

You can use the tab key to switch between fields and set the fields.

Note that: When we switch to the DHCP field, if we enterLong SpaceWhen displayed as [*], the following IP addresses, subnet masks, and default gateways cannot be modified, indicating that IP addresses and subnet masks will be dynamically allocated, if you need to set it yourself, you only need to enter a long space in DHCP, and then manually configure it.

After the settings are complete, click OK and press Enter !!!

Note:: At this time, the network environment we set does not take effect. to take effect, we must restart the NIC and use the following command:

[Root @ xiaoluo ~] #/Etc/rc. d/init. d/Network restartClosing the interface eth0: device status: 3 (disconnect) [OK] disable the loopback interface: [OK] The loopback interface is displayed: [OK] the pop-up interface eth0: active connection status: active connection path:/org/freedesktop/NetworkManager/ActiveConnection/5 Status: Activated connection activated [OK]

At this time, our network environment configuration takes effect !!!

We can use the ifconfig command to view the ip information on our Linux system (in windows, you can enter ipconfig in the command line)

[root@xiaoluo ~]# ifconfigeth0      Link encap:Ethernet  HWaddr 00:0C:29:B2:10:6A            inet addr:172.25.215.31  Bcast:172.25.215.255  Mask:255.255.255.0          inet6 addr: fe80::20c:29ff:feb2:106a/64 Scope:Link          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1          RX packets:19471 errors:0 dropped:0 overruns:0 frame:0          TX packets:5878 errors:0 dropped:0 overruns:0 carrier:0          collisions:0 txqueuelen:1000           RX bytes:2603354 (2.4 MiB)  TX bytes:523479 (511.2 KiB)lo        Link encap:Local Loopback            inet addr:127.0.0.1  Mask:255.0.0.0          inet6 addr: ::1/128 Scope:Host          UP LOOPBACK RUNNING  MTU:16436  Metric:1          RX packets:2906 errors:0 dropped:0 overruns:0 frame:0          TX packets:2906 errors:0 dropped:0 overruns:0 carrier:0          collisions:0 txqueuelen:0           RX bytes:238986 (233.3 KiB)  TX bytes:238986 (233.3 KiB)virbr0    Link encap:Ethernet  HWaddr 52:54:00:0A:92:EB            inet addr:192.168.122.1  Bcast:192.168.122.255  Mask:255.255.255.0          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1          RX packets:0 errors:0 dropped:0 overruns:0 frame:0          TX packets:325 errors:0 dropped:0 overruns:0 carrier:0          collisions:0 txqueuelen:0           RX bytes:0 (0.0 b)  TX bytes:88301 (86.2 KiB)virbr0-nic Link encap:Ethernet  HWaddr 52:54:00:0A:92:EB            inet6 addr: fe80::5054:ff:fe0a:92eb/64 Scope:Link          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1          RX packets:0 errors:0 dropped:0 overruns:0 frame:0          TX packets:0 errors:0 dropped:6460 overruns:0 carrier:0          collisions:0 txqueuelen:500           RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

2. Use ifconfig eth0 x. x to configure

We know that in Linux, ifconfig can be used to view ip information. here we can use ifconfig eth0 x. x to directly modify the ip address (Note: This modification method takes effect immediately, but is temporary. When we log out of the system and enter the system again, the ip information will become the information before the configuration.)

[Root @ xiaoluo ~] # Ifconfig eth0 172.25.215.1 // you can set the IP address to 172.25.215.1.

Other ifconfig commands:

Ifconfig *** ifconfig eth0 up enable the first Nic *** ifconfig eth0 172.25.215.1 netmask 255.0.0.0 use commands to configure the interface card address. * *** Ifconfig: view the attributes of the interface card, and then root the specific interface card. * *** Ifconfig eth0 down disables the first Nic.

3. By modifying the/etc/sysconfig/network-scripts/ifcfg-eth0 file, we can modify each of its attributes, including ip, subnet mask, default gateway, etc.

[root@xiaoluo ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0 

/*************************************** * If DHCP is a dynamic ********************************* ***/
EVICE = eth0 // Nic device name HWADDR = 00: 0c: 29: b2: 10: 6a // the mac address TYPE of the Computer = Ethernet // Ethernet UUID = b1eda882-d499-4804-b9de-f474cd90235aONBOOT = yes // whether the NIC is activated when the computer is started; optional values: yes/noNM_CONTROLLED = yesBOOTPROTO = dhcp // IP address Retrieval Method: Value: static/bootp/dhcp listen 6init = noUSERCTL = noDNS2 = 202.96.128.166DNS1 = 202.96.128.86PEERDNS = yes

/*************************************** * If you manually configure the ip address and other information ****************************** *********************/
DEVICE = eth0
ONBOOT = yes
BOOTPROTO = none
IPADDR = 192.168.1.8 // ip address of the Network Interface
NETMASK = 255.255.255.0 // Subnet Mask
GATEWAY = 192.168.1.1 // GATEWAY address
TYPE = Ethernet
USERCTL = no
PEERDNS = no
NETWORK = 192.168.1.0
BROADCAST = 192.168.1.255 // BROADCAST address

Similarly, after setting this method, the network configuration does not take effect. We also need to execute/Etc/rc. d/init. d/Network restartCommand will take effect !!!

 

This article mainly records three methods for configuring the network environment in the Linux system. You can configure the network environment as you like. You will continue to learn about Linux in the future !!!

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.