1. The back view

Are you playing a PC game? For now, this sentence is undoubtedly slightly ironic meaning, but also just to prove the importance of the network, so the network inside the computer is how to distribute, why you can access the Internet, Linux system needs to do what network configuration, here is a brief introduction to everyone;

2. Computer networking instructions

It should be emphasized here that in most cases, the Linux system used by the company is actually a virtual machine, that is, one server creates three to four virtual machines, and these three to four virtual machines are independent of each other when users use them. The advantage is that virtual technology makes better use of resources; The disadvantage is that if their host server’s entire disk fails, it can crash all four virtual machines at once. Therefore, the networking description here refers to the connection between the virtual machine, the host of the virtual machine, other hosts in the virtual host room, and the external network, as shown in Figure 2.1.

As shown in figure 2, the local area network (LAN) here can be understood as a room or a classroom, there are a lot of physical machine, these entities machine generally is connected to the same route, so general LAN real opportunities in the same network segment a network segment is not enough or too much (unless the machine itself deliberately configuration in different network segment), but the general machine is to be able to direct communication in a network, That is, physical machine 1 and physical machine 2 can communicate, but the physical machine needs to access the external network, such as Baidu, it needs to access the World Wide Web through the gateway; The virtual machine is how communication, virtual machine 1, 2, a virtual machine virtual machine 3 entities and their host machine machine 1 actually also can form a local area network (LAN), and the virtual machine is of the same network segment directly, but the host and the host is not necessarily the same network segment, associated with the network connection way you choose, the next section to tell, But host host must be agents can be used as a virtual machine, so the virtual machine can host 1 hosting entity machine 1 and machine 2 communication, also can through the entity machine 1 through the gateway to access the world wide web, but the real machine can not direct access to the virtual machine 1, 2 this and you also choose the types of network connection;

3. Classification of network connections

Vm networks are usually classified into bridge mode, NAT mode, and host-only mode.

3.1 Bridge Mode

As shown in Figure 3.1, RowYet’s computers are in a LAN and occupy the network segment 192.168.80.*. Now RowYet is playing with the virtual machines in the company, and using bridging mode means that the virtual machines inherit the NETWORK segment 192.168.80. 192.168.80.54. Advantages: VMS and physical machines in the same network segment can communicate with each other.

  disadvantages: Specifies the number of IP addresses occupied by VMS in the entire network segment. The total number of IP addresses in the entire network segment is 256.192.168.80.0 ~ 255) IP, excluding gateway (192.168.80.1), broadcast address (192.168.80.255), subnet (192.168.80.0), and some pre-reserved spare IP addresses, there are not many left, so it depends on the number of servers or computers in your entire LAN scale, if it is a small studio of about 20 people, it doesn’t matter, if it is a large scale, this mode is not suitable.

3.2 NAT Mode (Common Mode)

Figure 3.2 shows RowYet’s computers on a local area network (LAN) that occupies 192.168.80.*. Now RowYet is playing with virtual machines at the company. In Network Address Translation (NAT) mode, the virtual VM first creates a virtual NIC, and the virtual NIC creates a new Network segment, for example, 192.168.182.*, which is not in the same Network segment as the real IP Address.

Advantages: A new network segment is created for VMS, which does not occupy the IP address of the original LAN. Multiple VMS can be created on multiple VMS.

  disadvantages: The machine in the original LANLi 4, Wang 5Virtual machines cannot be found directly because they are not in the same network. But virtual machines can be foundLi 4, Wang 5The virtual machine can also be accessed on the World Wide Web. Why? The virtual machine can be accessed by proxy through RowYet’s physical machine 192.168.80.75Li 4, Wang 5And access the World Wide Web through gateways.

3.3 Host-only Mode

Only host mode is the virtual machine as a new server, entities with the host machine and other machines in a network it doesn’t matter, is independent and entities of the virtual machine can not access the host machine, can access the machine inside the LAN, also on the world wide web, similar to a single, less used in practical application.

4. Perform network configuration operations

4.1 Selecting the NAT mode

Open the VM software VM home page, as shown in Figure 4.1, and clickEdit vm SettingsIn the dialog box that is displayed, selectNetwork adapter, the choice ofNAT mode, click on thedetermineSave; Other VM configurations (CPU and memory) are also modified and saved here.

4.2 Viewing the Subnet, Gateway, and Subnet mask

Click edit on the menu bar of the VM home page, click virtual Network Editor, wait for a moment to pop out of the virtual Network Editor interface, select NAT mode inside, you can view the subnet and subnet mask below the page; Click NAT Settings on the page to jump to the NAT Settings page. On the new page, you can view the gateway, subnet, and subnet mask.

With these things you can configure the IP of the virtual machine.

4.3 Fixing the IP address and Enabling the Network Connection

Start the installed VIRTUAL machine, power on the vm, open the terminal, and enter information in the terminalifconfig, check the name of your network card. Blogger isens33;

[root@node7 ~] vi /etc/sysconfig/network-scripts/ifcfg-ens33

Copy the code

Vi command is the notepad under Linux, for vi or vim operation, you can refer to blog Linux commonly used vi/vim command, after entering the command, we can see:

TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=dhcp
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33
UUID=638db334-1b8c-4ed6-afb7-23a44a8713b1
DEVICE=ens33
ONBOOT=no

Copy the code

To modify the contents of the file, press the letter A:

  • willONBOOT=noInstead ofONBOOT=yes
  • willBOOTPROTO=dhcpInstead ofBOOTPROTO=static
  • Add the following lines of characters

IPADDR=192.168.144.137 NETMASK=255.255.255.0 GATEWAY=192.168.144.2 DNS1=119.29.29.29 or DNS1=192.168.144.2 ZONE=public domain

The final file is:

TYPE=Ethernet PROXY_METHOD=none BROWSER_ONLY=no BOOTPROTO=static DEFROUTE=yes IPV4_FAILURE_FATAL=no IPV6INIT=yes IPV6_AUTOCONF=yes IPV6_DEFROUTE=yes IPV6_FAILURE_FATAL=no IPV6_ADDR_GEN_MODE=stable-privacy NAME=ens33 UUID= 638DB334-1b8C-4ED6-AFb7-23a44a8713B1 DEVICE=ens33 ONBOOT=yes IPADDR=192.168.144.137 NETMASK=255.255.255.0 GATEWAY = 192.168.144.2 DNS1 = 119.29.29.29 ZONE = publicCopy the code

If ONBOOT is set to yes, the NIC boots with the system

BOOTPROTO is used to set the boot type of the NIC. DHCP indicates that the NIC automatically obtains an IP address. Static indicates that the NIC manually sets a static IP address. IPADDR=192.168.144.137 IPADDR Specifies the IP address (depending on the address obtained automatically) NETMASK Specifies the subnet mask. GATEWAY Specifies the GATEWAY. DNS1 Specifies the DNS IP address for Internet access 119.29.29.29 is a public DNS provided by domestic DNSpod company, 192.168.144.2 is the local DNS, both can be. DNS1=119.29.29.29 Optional ZONE=public Optional

After editing, press Esc and enter :wq! Press Enter, save and exit the document, and then restart the network service using the command systemctl restart network.service. After checking the IP address with IP addr, it was found that the IP address was our fixed configuration and would not change with the restart of the network service, indicating success.

[root@node7 ~]# systemctl restart network.service [root@node7 ~]# ip addr 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group defaul t qlen 1000 link/loopback 00:00:00:00:00:00 BRD 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: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP g roup default qlen 1000 link/ether 00:0 C :29:eb:97:18 BRD FF :ff:ff:ff: FF inet 192.168.144.137/24 BRD 192.168.144.255 Scope Global noprefixRoute ens33 valid_lft forever preferred_lft forever inet6 fe80::d01b:4c57:540a:9af3/64 scope link noprefixroute valid_lft forever preferred_lft forever [root@node7 ~]#Copy the code

4.4 fixing (hostname)hostname

#Modify the /etc/hostname file
sudo vim /etc/hostname
#Change the content to the hostname you want, then wq! Save exit, use

#It takes effect after restart. After restart, verify whether the IP and hostname are set by you
sudo reboot 
Copy the code

4.5. Firewall related operations

Sometimes because of the firewall interference others need to access your virtual machine frustration, design to disable the firewall command is as follows (CentOS7 version);

Sudo systemctl start firewalld sudo systemctl stop firewalld sudo systemctl start firewalldCopy the code

5. Remote connection tool

Operating in the Terminal command line of the original Linux makes me very uncomfortable. It is not convenient to copy and paste, and the syntax keywords are not highlighted. I just suffer from the lack of IP address. Now I have been assigned an IP address. Common remote terminals include X-shell,putty, MobaXterm, etc. Putty will hang after some incorrect instructions, and will not give a chance to retry, so the experience is not good. X-shell and MobaXterm have their own advantages and free versions, such as Table 5.1.1.

tool Remote login GUI upload and download files N screen linkage The stability of
putty Y N N poor
x-shell Y N N good
xftp N Y N good
MobaXterm Y Y Y good

Bloggers still prefer MobaXterm, after all, MobaXterm is functional = X-shel + XFTP, and MobaXterm has beautiful syntax highlighting, and supports dragging and dropping files. The most amazing thing is that MobaXterm can be linked with N screens, which is very suitable for cluster level configuration, as shown in Figure 10. Click Terminal on the menu bar and select Write Commands on All Terminals to enter this mode. To Exit, click Exit Mult-Execution mode (FIG. 5.1.4).

Open the installed MobaXterm, as shown in figure 5.1.1, click Session in the menu bar to pop up the pop-up box, click SSH of the pop-up box, write your Linux IP address on the Remote host, Specify your default login username, I’m writing root on my own machine. Port is usually the default remote port 22, unless modified; Select the Bookmark Settings section and write Comments(you are writing Comments to the machine). Once configured, click OK to jump to Figure 8.

By Figure 5.1.2, if all is Ok, the first login will ask you to enter your password,Password(Linux Password input will not be like Windows plain text or **** character prompt, Linux cursor will not move, don't be afraid, you just type, if you make a mistake, you can also delete Back if you remember the number of digits, press Enter to delete.)If you click yes, then the next login will not need a password, very convenient, clickYesThe jump in figure 9;

Figure 5.1.3 shows that MobaXterm has been configured and can be operated in this command line interface. It is very beautiful, and you do not have to bear the original interface any more. Enterprises often use this remote terminal to open a firewall and log in to the Linux server. You don’t usually have to go directly to a Linux machine.