Network Settings for CENTOS7

Source: Internet
Author: User
Tags first string

Required knowledge: The editing of files under Linux first gives the basis of the VI, there will be a detailed remote connection to the CentOS method

The basic concept of VI
Basically, vi can be divided into three operation states, namely command mode, insert mode and command mode (last line mode),
The functions of each mode are differentiated as follows:
1. Comand Mode: Controls the movement of the screen cursor, the deletion of the character or cursor, moves and copies a section and enters insert mode, or to last line mode.
2. Insert mode: Only in the insert mode, you can do text data input, press ESC and so on to return to Comand mode.
3. Last line mode: will save the file or leave the editor, you can also set the editing environment, such as searching for strings, listing line numbers, etc.

command to enter VI
VI FileName: Opens or creates a new file and places the cursor at the beginning of the first
VI +n FileName: Open the file and place the cursor at the beginning of nth (the plus sign here is the real input)
VI + FileName: Opens the file and places the cursor at the beginning of the last line
VI +/pattern FileName: Opens the file and places the cursor at the first string that matches the pattern
Vi-r FileName: The last time you were editing with VI, a system crash occurred, restoring filename
VI filename....filename: Open multiple files, edit them sequentially

Move Cursor Class command
H: Move the cursor one character to the left
L: Move the cursor right one character
Space: Move the cursor right one character
Backspace: Cursor moves left one character
K or ctrl+p: Move the cursor up one line
J or CTRL + N: Move the cursor down one line
Enter: Move the cursor down one line
W or W: Move the cursor right one word to the beginning of the word
B or B: The cursor moves left one word to the beginning of the word
E or E: Move the cursor right one word to the end of the word
): Move the cursor to the end of the sentence
(: The cursor moves to the beginning of the sentence
}: Move the cursor to the beginning of the paragraph
{: Cursor moves to end of paragraph
NG: Cursor moves to the beginning of nth
n+: The cursor moves down n rows
N: Move the cursor up n rows
n$: Cursor moves to end of Nth line
H: Move the cursor to the top row of the screen
M: Move the cursor to the middle line of the screen
L: The cursor moves to the last line of the screen
0: (note is the number 0) cursor moves to the beginning of the current line
$: Cursor moves to the end of the current line

Insert text Class command (switch to command mode method: ESC, command, and enter)
I: Before the cursor
I: At the beginning of the current
A: After the cursor
A: At the end of the current line
O: A new line below the current line
O: New row above the current line
R: Replace the current character
R: Replaces the current character and its characters until the ESC key is pressed
S: replaces the specified number of characters with the input text starting at the current cursor position
S: Deletes the specified number of rows and replaces them with the input text
NCW or NCW: Modifies a specified number of words
NCC: Modifying a specified number of rows

Delete command
NDW or NDW: Delete the n-1 characters at the beginning and after the cursor
Do: Delete to the beginning of the line
d$: Delete to end of line
NDD: Deletes the current line and its subsequent n-1 rows
X or x: Deletes a character, x deletes the cursor, and x deletes the cursor before the
Ctrl+u: Delete text entered under input mode

Exit (save or do not save exit) command

: Wq mandatory write file and exit. Force write even if the file is not modified, and update the file's modification time.

: X writes the file and exits. The file modification time is not updated unless the file is modified and the file modification time is updated.

: q! Do not save the file and Exit VI

Then the following

Installed on the virtual machine CentOS 7, at that time chose the minimum installation mode, the installation is completed immediately after the Ifconfig to view the IP address of the machine (LAN already has DHCP), found an error, prompted ifconfig command not found.

[Email protected] ~]# ifconfig

-bash:ifconfig:command not found

First, the habitual input echo $PATH (view the current PATH environment variable, the same function as the DOS Path command, note that the commands in the Linux system are case-sensitive), the results are as follows:

[Email protected] ~]# echo $PATH

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

From the results shown above, the placement of the hypervisor path/usr/sbin already exists, that is, the path of the external command. Directly with LS View/usr/sbin/directory, also did not see ifconfig, what is going on?

[Email protected] ~]# ls/usr/sbin/

I still do not forget, and then use the Find command also found Ifconfig?

[[email protected] ~]# Find/-name "Ifconfig"

At this point in the heart, should be a command to replace the ifconfig. On Baidu a check, sure enough, has used the IP command instead of ifconfig command. The common parameters for IP commands are listed below.

IP [Options] Action object {Link|addr|route ...}

# IP Link Show # Displays network interface information
# IP Link set eth0 UPI # Open Nic
# IP Link set eth0 down # close NIC
# IP Link set eth0 promisc on # open NIC Mixed mode
# IP Link Set eth0 promisc offi # Turn off the network card mix mode
# IP Link Set eth0 txqueuelen 1200 # set NIC Queue Length
# IP Link Set eth0 MTU 1400 # set NIC Maximum transmission unit
# IP Addr Show # Displays network card IP information
# ip addr Add 192.168.0.1/24 dev eth0 # set eth0 NIC IP address 192.168.0.1
# ip addr del 192.168.0.1/24 dev eth0 # remove eth0 NIC IP address

# IP Route List # view routing information
# IP route add 192.168.4.0/24 via 192.168.0.254 Dev eth0 # Set the gateway for 192.168.4.0 segment to 192.168.0.254, Data walk eth0 interface
# IP route add default via 192.168.0.254 Dev Eth0 # to set the defaults gateway to 192.168.0.254
# ip Route del 192.168.4.0/24 # Remove gateway for 192.168.4.0 network segment
# IP Route del Default # to delete the defaults route


After entering the IP addr command, I found that the ENP2S0 network card (this enp2s0 is My network card) does not have an IP address.

[[Email protected] ~]# IP addr

Since there is no IP address, go directly to the/etc/sysconfig/network-scripts directory to see the network card IP information configuration file name it.

[Email protected] ~]# ls/etc/sysconfig/network-scripts/
Ifcfg-enp2s0 ifdown-eth ifdown-post ifdown-team ifup-aliases ifup-ipv6 ifup-post ifup-team Init.ipv6 -global
Ifcfg-lo ifdown-ippp ifdown-ppp ifdown-teamport ifup-bnep ifup-isdn ifup-ppp ifup-teamport network-f Unctions
Ifdown Ifdown-ipv6 ifdown-routes ifdown-tunnel ifup-eth ifup-plip ifup-routes ifup-tunnel network-f Unctions-ipv6
IFDOWN-BNEP ifdown-isdn ifdown-sit ifup ifup-ippp ifup-plusb ifup-sit ifup-wireless


From the results, the configuration file name of the previously saved NIC IP information is also changed from the previous ifcfg-eth0 to Ifcfg-enp2s0, well, since you gave him such a name, I'll use it first. Cat First Ifcfg-enp2s0
[Email protected] ~]# CAT/ETC/SYSCONFIG/NETWORK-SCRIPTS/IFCFG-ENP2S0
hwaddr=00:e0:69:01:6a:96
Type=ethernet
Bootproto=dhcp
Defroute=yes
Peerdns=yes
Peerroutes=yes
Ipv4_failure_fatal=no
Ipv6init=yes
Ipv6_autoconf=yes
Ipv6_defroute=yes
Ipv6_peerdns=yes
Ipv6_peerroutes=yes
Ipv6_failure_fatal=no
Name=enp2s0
Uuid=5b0a7d76-1602-4e19-aee6-29f57618ca01
Onboot=no

From the above configuration to see although bootproto=dhcp, but onboot=no, here with VI will onboot=no change to Onboot=yes, and then restart CentOS.

[Email protected] ~]# Shutdown-r

After reboot, enter account number and password enter the command prompt operator to continue to view network card information with IP addr. The results are as follows:
[[Email protected] ~]# IP add
1:lo: <LOOPBACK,UP,LOWER_UP> MTU 65536 qdisc noqueue State UNKNOWN
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:ENP2S0: <BROADCAST,MULTICAST,UP,LOWER_UP> MTU Qdisc pfifo_fast State up Qlen 1000
Link/ether 00:e0:69:01:6a:96 BRD FF:FF:FF:FF:FF:FF
inet 172.8.1.200/24 BRD 172.8.1.255 Scope Global ENP2S0
Valid_lft Forever Preferred_lft Forever
Inet6 FE80::2E0:69FF:FE01:6A96/64 Scope link
Valid_lft Forever Preferred_lft Forever

As seen from the above results, the IP address assigned to by DHCP is 172.8.1.200, although it is a test machine, but in order to facilitate future remote connection, we still configure a fixed IP for this machine.

Open Ifcfg-enp2s0 with VI, enter the following parameters, and then use # to BOOTPROTO=DHCP comments.
ipaddr0=172.8.1.211
Prefix0=24
gateway0=172.8.1.1
dns1=172.8.1.1

The complete parameters are as follows, OK, the network is well-equipped. Continue with other functional tests tomorrow.
[Email protected] ~]# CAT/ETC/SYSCONFIG/NETWORK-SCRIPTS/IFCFG-ENP2S0
hwaddr=00:e0:69:01:6a:96
Type=ethernet
#BOOTPROTO =DHCP
Defroute=yes
Peerdns=yes
Peerroutes=yes
Ipv4_failure_fatal=no
Ipv6init=yes
Ipv6_autoconf=yes
Ipv6_defroute=yes
Ipv6_peerdns=yes
Ipv6_peerroutes=yes
Ipv6_failure_fatal=no
Name=enp2s0
Uuid=5b0a7d76-1602-4e19-aee6-29f57618ca01
Onboot=yes
ipaddr0=172.8.1.211
Prefix0=24
gateway0=172.8.1.1
dns1=172.8.1.1

After setting the IP address of the virtual machine, we can easily connect the virtual machine remotely.

Network Settings for CENTOS7

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.