Linux [Practice] - Disk Partitioning, Network Configuration

content

1. Disk partition

1. Overview of Disk Partitioning

2. Disk partition instance

3. Query the disk status

4. Other commands for disk conditions

2. Network configuration

1. Network overview

2. Configure the Linux network environment

3. Set the hostname and host mapping

4. Supplementary hostname resolution process


1. Disk partition

1. Overview of Disk Partitioning

        The Linux operating system has only one root directory, and the root directory is divided into several sub-directories for use. Each partition in the Linux operating system is part of the entire file system, and each partition in the hard disk will be mounted. to a directory in the file system.

Linux hard disks are divided into IDE hard disks and SCSI hard disks. The drive identifier of IDE hard disks is " hdx~ ":

  • "hd" indicates the type of device where the partition is located
  • "x" indicates the disk number, a is a basic disk, b is a basic slave disk, c is an auxiliary master disk, and d is a auxiliary slave disk
  • "~" means partition, the first four partitions are primary or extended, respectively represented by numbers 1 to 4, starting from 5 to become logical partitions

For example, the identifier hda1 represents the first primary or extended partition on an IDE hard disk;

The drive identifier of SCSI hard disk is " sdx~ ", except that "sd" is used to indicate the device type, the rest are the same as IDE hard disk. At present, the mainstream hard disk is SCSI hard disk.

We can use the command lsblk or lsblk -f to view all hard disk partitions and device mounts. The following SCSI basic disk has 1 and 2 primary or extended partitions:

The difference between using the lsblk -f command is that this command is more detailed than the information viewed by lsblk;

2. Disk partition instance

Creating a new disk, partitioning, mounting, and deleting requires the following steps:

(1) Add a hard disk

        We first add a hard disk in the Linux system, enter the "Menu", select "Settings", add a hard disk in the device list, then click "Next" and set the disk size and then restart the system.

Click OK after adding the new hard disk;

After restarting the system, check the partition status of the hard disk. There is a new SCSI hard disk sdb with a size of 1G as follows, but there is no partition at this time;

(2) Create a partition

        The partition command is fdisk disk . You need to know that the newly added hard disk is in the device folder of the Linux operating system, which is the /dev directory, so we use the command fdisk /dev/sdb to partition the hard disk sdb, and then follow the prompts as follows operate:

Note: In the last step of the partition operation, you must enter w to write to the disk and exit, otherwise the previous operations will not take effect.

At this time, we will check the hard disk and partition situation again. The new hard disk sdb has a new partition sdb1;

(3) Partition formatting

        The format partition instruction is  mkfs -t ext4 partition , where ext4 represents the partition type; next we format the partition sdb1:

In addition, if you want to know whether a partition has been formatted, you can use the command lsblk -f to view the detailed information of the partition. Unformatted partitions do not have a unique identifier (UUID) attribute.

(4) Mount the newly created partition to the directory

        According to the partition principle, each partition is closely related to the file system, so the partition can only be used if it is mounted to a certain directory. The mount command is the mount partition mount point ;

We create a new directory newdisk for mounting (recommended and switched to the root directory or other directory creation, because the pony was unsuccessfully mounted when the main directory was created) ;

At this point, check the partition again, the new partition sdb1 already has the mount point newdisk;

So far, the new partition has been successfully created and mounted to the directory. The files created in the directory in the future are actually saved to this partition.

Tip: After using the mount command to mount, the mount relationship will disappear after restarting the system. To avoid repeated operations of mounts, permanent mounts can be performed.

(5) Delete (uninstall) the mount relationship

        To delete the mount relationship between a partition and a directory, use the command umount partition or umount mount point . The following mount relationship has been deleted;

3. Query the disk status

        When a file is created in a directory, the file will be saved to the disk partition that has a mount relationship with the directory, and the disk storage space will become smaller and smaller. In order to ensure the normal use of the disk, we must always know the usage of the system disk.

Use the command df -h to query the disk status , as follows; when the usage exceeds 80%, relevant measures should be taken, such as clearing space, adding disks or partitions, etc.;

In addition to querying the system disk status, you can also use the command du -h /directory to query the usage status of the disk corresponding to the specified directory. When the command du -h is used directly without writing a directory, it defaults to the current directory;

4. Other commands for disk conditions

  • ls -l directory | grep "^-" | wc -l   //Count the number of files in a directory
  • ls -l directory | grep "^d" | wc -l   //Count the number of directories in a directory
  • ls -lR directory | grep "^-" | wc -l   //Count the number of files in a directory including its subfiles
  • ls -lR directory | grep "^d" | wc -l   //Count the number of directories in a directory including its subdirectories
  • tree directory   //Display the directory structure in a tree structure, provided that tree has been installed (installation command: yum install tree )

2. Network configuration

1. Network overview

        In the past operations, Xiaoma demonstrated the Linux operating system in the form of a virtual machine, that is, to create a virtual machine in the Windows environment, and use the Linux system in the virtual machine to simulate the mutual operation between Windows and Linux. .

Use the command ifconfig to view the network configuration in the Linux operating system ;

Use the command ipconfig to view the VMnet8 network configuration in the Windows operating system ;

It can be seen from the above operation that the networks of the Windows side and the Linux side are in the same network segment, which is 192.168.65.xx, so network communication can be performed between the two (network communication can only be performed on the same network segment ).

To test whether the two hosts can be connected, you need to use the command to ping the destination host ip ; test whether the Linux system can be connected to the Windows system as follows, and it can be connected;

Test whether Baidu can be connected in the Linux operating system;

2. Configure the Linux network environment

Method 1: Obtain ip automatically

        After logging in to the Linux operating system, the default is to obtain the IP automatically. This method can effectively avoid IP conflicts, but the IP obtained each time may be different.

At work, the Linux system may need to run as a server, and a fixed IP address is required at this time, so it is not recommended to use the automatic acquisition method to obtain the IP.

Click "Application"-->"System Tools"-->"Settings"-->"Network"-->"IPv4" to view the current network configuration;

Method 2: Manually specify the ip

        To manually specify ip, you need to modify the configuration file, use the vi/vim editor to modify the content of the /etc/sysconfig/network-scripts/ ifcfg-ens33 file;

First vim enters ifcfg-ens33, the initial state of the file is as follows;

Next, press i to enter the insert mode to modify, the modification is as follows;

After the modification is completed, wq save and exit;

Now we have set the ip of the Linux virtual machine to 192.168.200.131. In order not to affect the connection with widows, we also need to modify VMnet8 to the same network segment 192.168.200.xx;

After the setting is completed, restart the network service service network restart , or restart the system , and the new fixed ip will take effect; at this time, enter the Linux system to check the ip, and the ip address has been updated;

Viewing VMnet8 in Windows has also been modified;

At this point, both ends can ping each other, indicating that the new network ip has been configured successfully;

3. Set the hostname and host mapping

(1) Set/modify the hostname

        The Linux operating system can set and modify the host name, and use the command hostname to view the current host name; my Linux initial host name is as follows:

Modifying the hostname requires modifying the content of the file /etc/hostname;

After the modification, restart the system and the new host name will take effect;

(2) Set the host mapping

In addition to pinging the target host ip , you can also         test the connectivity by pinging the target host name , provided that the host mapping must be set first;        

In the Windows operating system, it is specified in the C:Windows\System32\drivers\etc\hosts file;

Add a new sentence [the ip host name to be specified];

After that, you can ping the target hostname on the Windows side to test the connectivity with Linux;

In the Linux operating system, it is specified in the /etc/hosts file, and the rest of the operations remain unchanged and are omitted here.

4. Supplementary hostname resolution process

        hosts is a text file used to record the mapping relationship between ip and hostname (hostname); DNS domain name is a distributed database that maps domain names and ip addresses to each other on the Internet.

        When the user enters a domain name in the browser, the browser will first check whether there is an ip address resolved by the domain name in the browser cache, and if so, return the ip to complete the resolution, if not, then check the DNS resolver cache of the operating system. Return directly to ip to complete the parsing. If the mapping corresponding to the resolved IP address is still not found in the DNS resolver cache, go to the hosts file of the system to look it up. If the hosts are not found, go to the domain name service database of the public network to look up. exist".

        To put it simply, there are four searches in total: look up browser cache --> look up system DNS cache --> look up hosts file --> look up public network database.

Guess you like

Origin blog.csdn.net/weixin_53072519/article/details/123960179
Recommended