Linux basic commands

Time:2019-10-10

Linux commands

Explanation:
    [[email protected]linux01 Desktop]#
    Root User, Super User
    Linux01 host (host name: linux01.hadoop.com)
    Desktop user directory (working directory)
    # Super User ($for ordinary users)
Common Operations
    Historical commands (use_to obtain historical commands)

    Tab completion (input filename completion or prompt)

    clear (ctrl+l)

    pwd (print name of current/working directory)
        View the current location
        Home directory root user/root
                Ordinary user Hadoop / home / Hadoop

    Man command quits by Q
    Command-help
1. ls (list directory contents)
2.  cd
/ Current Directory
. / Superior Catalogue
cd ~
CD home directory
3. mkdir: Create directories
Multilevel directory-p
mkdir -p a/b/c
4. touch: Change file attributes
5. rmdir deletes empty directories
rmdir test
6. RM deletes files or directories
- R iteration
- F Force: Don't ask me to delete directly
7. cp: replication
- r: Recursive copy directory
8. MV (mobile clipping, renaming)
9. cat (see less content)
10. more
Page down (space)
Look down line by line (return)
Press Q or Ctrl + C to terminate exit status
11. less
12. head
13. Tail-3 document
View the last three lines of the file
- F View dynamically, with file descriptors
- F Dynamic View, Following File Name
14. Shut down
shutdown -h now
init 0
15. Restart
reboot
init 6

VI Editor

  1. Command mode
    NDD deletes n rows starting from the current row
    NYY copies the n rows at the beginning of the current row
    P pasted behind the current line
    U revocation
  2. Insert mode
    In command line mode, press a, i, o
    A: enough cursors
    I: Cursor position
    O: Insert next line of cursor
  3. Bottom mode
    In command line mode
    Type: Enter bottom mode

    W save, Q quit,! Mandatory
    WQ saves and exits
    Q! Force exit without saving modifications

network configuration

Su - Switch to Super User
1) The host name cannot begin with a number,. And contains special characters (*@$)
    Hostname view hostname
    Host name centos01 temporarily modifies host name, restart invalid
    Vi/etc/sysconfig/network permanent modification, restart effective
2) Modify IP
    1) Interface modification
    2) # vi  /etc/sysconfig/network-scripts/ifcfg-eth0
        ONBOOT = yes // boot-up automatic connection network
        BOOTPROTO = static // Set to static DHCP as dynamic, none as unspecified
        # service network restart
    3) Modify Host Mapping Virtual Machine
    # vi /etc/hosts
    192.168.247.110    centos01

    Windows
    C:\Windows\System32\drivers\etc\hosts


Windows Ping server
    ping ip
    Ping host name
Server Ping gateway

Users and User Groups

User group: to facilitate the management of users, for example: schools in order to facilitate the management of students, students are divided into classes.

  • View Users

cat /etc/passwd

root​ ​ ​:x:​0:0:root:/root:/bin/bash
Root username
X password
0 user ID
0 user group ID
Root user description
/ Root User Home Directory
/ shell used by bin/bash users

  • View User Groups

cat /etc/group

When a user is created, a user group with the same user name is created by default.

1. User type

  1. Root users, super users, the highest privileges, in the actual production environment, try not to use root users
    User UID 0
  2. Ordinary users
    User UID 500 starts
  3. Pseudo-user system assigns ID numbers to some processes, which are pseudo-users. They can’t login and have no home directory.
    UID ranges from 1 to 499

2. Create delete users

  1. Creating Users
    ​ # useradd xiefei
    # Passwd Password Setting or Modifying Password
  2. delete user
    # Userdel-r xiefei deletes users completely

    - R Remove User Home Directory Recursively

3. Creating User Groups

# groupadd user group

4. Switching Users

# Su – Switch to root user
# Switching Su – Hadoop to Hadoop
The difference between Su and Su – is that the former handles users while the latter handles users and user environments
# Exit exits the user

User File and Directory Rights

drwxr-x–x
D Represents Catalogue
– Representative Documents
Permissions of user (u) to which RWX belongs
Permissions of user group (g) to which R-X belongs
– x Privileges of Other Users (o)
(Users are students, subordinate groups are classes, other students give examples to analyze)

R readable
W Writable
X executable
RWX readable, writable and executable
R-X readable and executable

RWX can also be expressed as 1117
rw- 110 6
r-x 101 5
r– 100 4

  1. Modify permissions

# Chmod 764 test.c is modified to be readable, writable and executable
# CHMOD U + X test. C adds execution privileges to all users
# CHMOD G + W test. C adds write permissions to all user groups
# Chmod O-X test deletes execution privileges for other users
# Chomd 777-R test/Recursively modify all file permissions for test

  1. Modify the user to which it belongs

# Chown Hadoop msg.txt modifies msg.txt to all Hadoop

  1. Modify the user group to which it belongs

​ # chgrp hadoop msg.txt

  1. Modify Users and User Groups

​ # chown hadoop:hadoop -R hadoop/

  1. Add users to user groups and delete users to view user groups to which users belong

    # gpasswd -a hadoop mygroup
    # gpasswd -d hadoop mygroup
    # groups hadoop

Pipeline Character |, Added/Overlay Symbol

  1. Pipeline Character|

Pass the output of the previous command to the subsequent command processing
​ # cat /etc/passwd | more

  1. Using grep filtering

​ # cat /etc/passwd | grep ‘root’

  1. Filtration conditions

​ # ll /etc/ | grep ‘sysconfig’
# ifconfig | grep’inet’view IP

  1. Add > Cover >

​ # ll > test.txt
​ # ll >> test.txt

  1. wc (word count)

– L Statistical rows
– W statistical word
​ # wc -l /etc/passwd
​ # wc -w test.c

  1. Statistical file or directory size

​ # du -sh /lib

  1. Display the current system process

​ # ps -ef
​ # ps -ef | grep ‘java’

Search command find

Grammatical format:

Find range condition

  1. By file name

​ # find / -name init
Fuzzy queries with keywords: $find/etc/name*work
Find the file at the beginning of the keyword: $find / etc / name init*
Match a single character $find / etc / name???
Case-insensitive matching $find/etc/iname???

  1. By file size

Option: -size
Specify: +greater than, -less than, no sign equals
​ $ # find /etc/ -size +2M

  1. By user, user group

​ # find /root -user hadoop
​ # find /root -group hadoop

  1. By file type

# find/etc/name*work-type f file
# find/etc/name*s-type D directory

Sudo permissions (# visudo)

​ root ALL=(ALL) ALL
​ user01 ALL=(root) NOPASSWD: ALL

The first ALL refers to the host in the network, which indicates that the user 01 can execute the following commands on the host.
The ALL in the second bracket refers to the target user, who is the identity to execute the command.
The last ALL is the command.

Compression and decompression

Windows is common:.Rar.zip
Linux is common:.Tar.tar.gz.gz

  1. Compression and decompression to.Tar

Tar CVF content.tar Main.java msg.txt compresses Main.java msg.txt into context.tar
Tar xvf content. tar-C test extracts content into the test folder

  1. Compression and decompression to.Tar.gz

# tar-zcvf test.tar.gz. / Compress the current directory
# Tar-zxvf test.tar.gz-C. / Compressed files are pressurized to the current directory

  1. Compression and decompression:.Gz does not retain source files

Compression
​ $ gzip hello.mp4
Decompression
​ $ gunzip hello.mp4.gz
Options:
​ -z, –gzip, –gunzip, –ungzip filter the archive through gzip
​ -c, –create create a new archive
​ -x, –extract, –get extract files from an archive
​ -v, –verbose verbosely list files processed
​ -f, –file=ARCHIVE use archive file or device ARCHIVE
F must be followed by the filename to be processed

RPM package management

  1. View Installation Software

​ $ rpm -qa | grep jdk
To see which RPM package a file belongs to
​ # rpm -qf /etc/ntp.conf

  1. Installation and unloading

(a) Installation:
​ # rpm -ivh tree-1.5.3-3.el6.x86_64.rpm
Usage: rpm-ivh software name (.rpm)
Option: -i install represents installation
– VH shows detailed progress
​ # rpm -ivh tree-1.5.3-3.el6.x86_64.rpm
B) Unloading
Option: – e stands for uninstall — erase
Usage: rpm-e software name (.rpm) — nodeps (no validation dependency uninstall)
​ # rpm -e tree-1.5.3-3.el6.x86_64 –nodeps
C) Uninstall with JDK
​ $ sudo rpm -e java-1.7.0-openjdk-1.7.0.45-2.4.3.3.el6.x86_64 –nodeps
​ $ sudo rpm -e java-1.6.0-openjdk-1.6.0.0-1.66.1.13.0.el6.x86_64 –nodeps
// Re-entry into force
​ $ source /etc/profile

  1. Install JDK

    1. Create two directories

Deposit directory of sudo mkdir/opt/software//installation package
Sudo MKDIR / opt / modules // / unzipped installation directory

2. Users and user groups that modify directories

​ $ sudo chown user01:user01 /opt/software/ /opt/modules/

3. Upload and decompress JDK

​ $ tar -zxf jdk-7u67-linux-x64.tar.gz -C ../modules/

4. Configuring environment variables

​ # vi /etc/profile
Add at the end
​ #JAVA_HOME
​ export JAVA_HOME=/opt/modules/jdk1.7.0_67
​ export PATH=$PATH:$JAVA_HOME/bin

5. Make it effective

​ #source /etc/profile

6. Check for success

​ java -version

yum

  • The premise is that the external network must be connected.
  • Used to solve RPM dependency problem
  • Convenient, Fast and Automatic Resolution Dependency
  1. query

# Yum list // / View the software owned on the yum source
# Yum list installed | more // / view RPM packages installed in the system is equivalent to rpm-qa
​ $ sudo yum list installed | grep tree

  1. install

​ # yum install httpd-devel.x86_64
Option: install suffix does not need to be added. RPM can use commands directly
Option: -y, indicating direct automatic confirmation
​ # yum -y install httpd-devel.x86_64
​ $ sudo yum install tree

  1. uninstall

​ # yum -y remove httpd-devel.x86_64
​ $ sudo rpm -qa | grep tree

  1. Common problem

Lack of access to the Internet and poor network quality

System Management Command

  1. Top Views System Resources – > Equivalent to Task Manager

Update every 3 seconds
Quit browsing by Q

  1. Free Viewing Memory Information

Option: -m, which is displayed in MB format

  1. Df-l View Hard Disk Partition Information
  2. Ps-ef View System Process
    ps -ef | grep crond

JPS view Java processes running on the system

  1. Killing kills ongoing processes -“used in conjunction with JPS

Option: -9
​ kill -9 【pid】

  1. ifconfig
  2. Ping detects network quality and network connection

Ping host name
IP address
Domain name

  1. Netstat View Network Port

Options:
– t # Monitor the process of TCP protocol
​ -l #listenning
– n # Display port number information
– P# Display Process PID
​ netstat -antp

  1. JPS view running Java processes
  2. vmstat 2 5

State values of servers at given intervals, including CPU usage, memory usage, virtual memory swap, IO reads and writes
2 Represents interval time
5 Represents the number of acquisitions

Close firewalls and security subsystems

In online applications (distributed), firewalls are usually closed. By default, firewalls restrict network access to some applications (such as RPC communication ports) for security reasons. In order to ensure the stability of multi-computer communication, you can choose to close the firewall.

  1. Close the firewall and start it off (/etc/inittab start level)
1. Close Linux Firewall

    # Service iptables stop # Close the firewall
    # Service iptables status # View firewall status
     iptables: Firewall is not running.

    2. Setting up the Firewall to Start Up without Turning on
    # chkconfig iptables off # # no random boot settings boot up using on

    3. View firewall boot settings
    $ sudo chkconfig --list | grep iptables
  1. Close the security subsystem
# vi /etc/sysconfig/selinux

Modify the following SELINUX = enforcing toSELINUX=disabled

Shell programming

Specification of shell scripts

  1. Line 1: #! / Beginning of bin/sh or #! / Beginning with bin/bash

Declare what kind of shell it is

  1. Notes:#
  2. The shell script ends with. sh
  3. There are two basic ways to execute a shell:

1) sh hello.sh# Execute shell scripts
2). / hello. sh # This way requires the script to have execution privileges

The shell variable num = 123; STR = Hello World
Define variables without data types
Referencing a variable requires adding a $symbol before the variable

Shell variable type

environment variable

Save the variables used by the system at runtime
》 User variables
Bash_profile has this file in each user’s home directory to save environment variables for each user
》 System variables
/ etc/profile: Configuration file for the global validity of the system

Location variable

Save the parameters passed to the script in the location variable
To facilitate the reference of these variables in scripts
Bash defines nine location variables: $1… $9
$0: Represents the name of the current script

#! /bin/sh

Echo: "This is the first variable $1"
Echo: "This is the first variable $2"
Echo: "This is the first variable $3"
Echo: "This is the first variable $4"
Echo: "This is the first variable $9"

Predefined variables

$0: script name
$!: The PID number of the last process running in the background
$: ID number of the current process
$#: Number of parameters for the current shell
Display all parameter contents (overall)
[email protected]: Displays all parameter contents (read one by one)
$? Judgment: Representatives of program exit (returning 0 represents success, not 0 represents failure)

#! /bin/sh
Echo "script name: $0"
Echo: "ID number of current process: $"
Echo: "Number of parameters for the current shell: $"
Echo "Display all parameter contents (read one by one: [email protected]"

aaaaa
# A value of 0 is printed here, indicating that the previous line of command execution was wrong.
echo $?

Custom variables

  1. Grammatical Format:

​ name=value
No spaces on either side of the equal sign
Variables are case sensitive
The value of the call variable $name

  1. Assignment of variables

1. Direct assignment tag1 = 112
​ 2. tag2=$tag1
​ 3. szie=ls ~/ Assign commands to variable floats or back Quotes
The shell string/command (echo):

#! /bin/sh
# No spaces around assignment numbers
# Variables have no type
numOfPerson=100;
echo $numOfPerson


# Assign the variable numOfPerson to n
n=$numOfPerson
echo "n=$numOfPerson"

# Assign the contents executed by ls-l/et to str
str=`ls /etc`

The distinction between “‘”

Echo can be output without quotation marks
Echo plus single quotation mark # single quotation mark content output as it is, single quotation mark will deprive all characters of the special meaning
str=’hello $num’
Echo plus double quotation marks # double quotation marks can output variables, output “etc., need to be escaped
str=”hello $num”

String splicing of shell
​ str=”hadoop”
A= “Hello & dollar; str”

A= "Hello"$str

Shell operation

  1. arithmetic

The first way to write $(())
The second way of writing $[]
The third way to write expr expressions is to accept only numeric values, expr itself is a shell command, and the output uses inverted Quotes

​            a=6;b=5

​            echo $((a+b))

​            echo $(( $a * $b ))



​            echo $[a+b]

​            echo $[ $a * $b ]



​            expr $a - $b

​            expr $a \* $b

  1. Logical operation

-》&& Logic and (Command Controller)
CMD1 & & cmd2 // / The previous command executes successfully before the subsequent command is executed
-》|| Logic or
CMD1 | | cmd2 // / The previous command fails to execute the subsequent command
-》 No logical symbols
​ cmd1 ; cmd2

Built-in test judgment

  1. Two Ways of Writing
​            a=6

​            b=9

# Spaces between the first variable and comparator can be omitted

​            if test 6 -gt 9

​            then

​                echo bigger

​            fi

# The space between the second variable and the comparator must be

​            if [ $a -lt $b ]

​            then

​                echo smaller

​            fi
  1. NUMERICAL COMPARISON

– EQ # equals
– Ne # not equal is not equal to
– GT # greater than
– Ge # greater equal greater than or equal to
– LT # little that is less than
– Le # little equals less than or equal to
Note: In numerical comparison, symbols such as “>”<“cannot be used for comparison.
When testing or [] testing, there must be a space

test $1 -gt 60* **-a** *$1 -lt 70Use within the same condition

[ $1 -ge 70* **-a** *$1 -lt 80 ]

elif [ $1 -ge 60 ] && [ $1 -lt 70 ]

$[“990” – Le “995”] & & [“123” – GT “33”] Here you use&&

  1. String comparison

= equal to
!= Not equal to
– Z $str length 0 is true
– If the length of n “$str” is not zero, it is true
The $str string is true if it is not null

​            #!/bin/sh

​            str1="abc"

​            str2="abc"

​            str3="cde"

​            str4=

​            if [ $str1 = $str2  ]

​            then

Echo STR1 and STR2 are equal

​            fi

​            if [ $str1 != $str3  ]

​            then

The echo STR1 and str3 are not equal

​            fi



​            if [ -z $str1  ]

​            then

The echo STR1 length is 0

​            fi

​            if [ -n "$str3"  ]

​            then

The length of echo str3 is not zero

​            fi

​            if [ $str1  ]

​            then

Echo STR1 is not empty

​            fi

​            if [ $str4  ]

​            then

Echo str4 is not empty

​            fi
  1. Document testing

– D (directory) is true if it is a directory
– F (file) If it is a file, it is true
– R is true if it is readable
– W is true if it is writable
– x exec is true if it is executable
Note: Readable, Writable and Executable are privileges for users who execute scripts

​            #!/bin/sh

​            if [ -d $1  ]

​            then

Echo is a directory

​            fi

​            if [ -f $1  ]

​            then

Echo is a document

​            fi

​            if [ -r $1  ]

​            then

Echo is readable

​            fi

​            if [ -w $1  ]

​            then

Echo is writable

​            fi

​            if [ -x $1  ]

​            then

Echo is executable

​            fi
  1. Logical connectors:

Three types:
1. No!
2. and-a
3. or-o

​            if [ -f  $1 -a $2 -gt 5]

​            then

​                echo  \  is $2

​                echo  "\ is bigger than 5 "

​             fi

Process Control

  1. if

If conditional judgement
​ then
​  command
Elf conditional judgment
​ then
​  command
Elf conditional judgment
​ then
​  command
​ …
​ else
​  command
​ fi



​        #!/bin/sh

​        echo please type age

​        read age

​        if  test $age -ge 0 -a $age -lt 3

​        then

​            echo  baby

​        elif [ $age -ge 3  -a $age -lt 7 ]

​        then

​            echo child

​        elif [ $age -ge 7 ] && [ $age -lt 18 ]

​        then

​            echo teenager

​        elif test $age -ge 18 && test $age -lt 40

​        then

​            echo youth

​        elif test $age -ge 40 && [ $age -lt 60  ]

​        then

​            echo man

​        else

​            echo older

​        fi
​        #!/bin/sh

​        # read socre  and choose level

# Read is equivalent to scanner in Java, an interactive command that reads input from a device.

Echo: "Please enter student score:"

​        read score

​        if test $score -ge 90;

​        then

​                echo level A;

​        elif [ $score -ge  80  -a  $score -lt 90 ]

​        then

​             echo "level B";

​        elif test  $score -ge  70  -a  $score -lt 80

​        then

​             echo "level C";

​        elif [ $score -ge  60 ] && [ $score -lt 70 ]

​        then

​             echo "level D";

​        else

Failure of echo;

​        fi
  1. Loop statement

1) For cycle
​ I)
For ((Initializing variable values; Ending loop conditions; Loop control statements)
​ do
Circulating body
​ done

​                #!/bin/sh

​                sum=0

​                for ((i=0;i<10;i++))

​                do

​                    echo $i

​                    sum=$[ $sum + i ]

​                done

​                echo $sum

2) The second grammatical format:

For variable in value 1 value 2… Value N

​ do

Circulating body

​ done

​                #!/bin/sh

​                for MONTH in Jan Feb Mar Apr May Jun July Aug Sep Oct Nov Dec

​                do

​                    echo $MONTH

​                done
​                #!/bin/sh

​                for file in `/bin/ls $1`;

​                do

​                echo $file;

​                done
  1. While loop

    1.

While [condition cyclic condition]
​ do
​ #statements
# [circulatory body]
# [Cyclic Control]
​ done

​            #!/bin/sh

​            i=1

​            while [ $i -le 10 ]

​            do

​                sum=$((sum+i))

​                i=$[ i + 1 ]

​            done

​            echo $sum
​            #!/bin/sh

​            i=1

​            sum=0

​            while test $i -le 10

​            do

​                sum=$[ $sum + $i ]

​                i=`expr $i + 1`

​            done

​            echo $sum
  1. The second grammatical format:

​ while read -r line

​ do

# [circulatory body]

​ done

​            #!/bin/sh

​            #Read /ect/sysconfig/network-scripts/ifcfg-eh0 and print out

​            FILE=/etc/sysconfig/network-scripts/ifcfg-eh0

​            while read -r line

​            do

​                echo $line

​            done < $FILE

In read

Parameter-r shielding,

If this option is not available, it will be used as an escape character or, in some cases, a normal character.
Command < file redirects input to file.

  1. Case is similar to swich case in Java

The first grammatical format:

​            #!/bin/sh

Echo'enter the number between 1 and 4:'echo'you enter the number:'read aNum case $aNum in 1';'echo' you choose 1';'echo'you choose 2';'echo' you choose 3';'echo'you choose 4'; *) echo'You didn't enter a number between 1 and 4'r'm;; ESAC

The second grammatical format:

​            #!/bin/sh

​            echo "input from :one two three ....."

​            read input

​            case $input in

​                one | two) echo "your input is one or two"

​                ;;

​                three | four) echo "your input is three or four "

​                ;;

​                five) echo "your input is five"

​                ;;

​                *) echo your input is $input

​    ;;

​            esac


Calls to shell scripts (to call another script in one script)

Which touch # View shell location

​            #!/bin/sh

​            source /home/hadoop/shell/hello.sh

Date command

  1. display system time

1. date CST Central Standard Time
​ Mon Jun 5 15:11:44 CST 2017
2. date-R time zone
​ Mon, 05 Jun 2017 15:14:44 +0800

  1. format date

​ $ date ‘+%Y-%m-%d %H:%M:%S’
​ 2017-05-02 11:20:10

Setting time

Option: -s
Usage: # date-s “2016-12-08 10:43:00”

Ntpdate command

Usage: ntpdate Network Time Server (182.92.12.11)

​ sudo ntpdate ntp.api.bz

Crontab Planning Tasks

  1. ) Periodic execution of planned tasks
  2. Options to use:

Crontab-l (list) # View the current list of planned tasks
Crontab-r (remove) # Delete planned tasks
Crontab-e (eidt) # Editing Periodic Planning Tasks

  1. The process name is crond

Ps-ef | grep crond $to see if this process is open
The default process is open, and if it is not, it can be opened manually by command
​ # service crond status
​ # service crond start
​ # service crond stop
​ # service crond restart

  1. Example of job definition:
​        # .---------------- minute (0 - 59)
​        # |  .------------- hour (0 - 23)
​        # |  |  .---------- day of month (1 - 31)
​        # |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
​        # |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
​        # |  |  |  |  |
​        # *  *  *  *  * user-name command to be executed
​         *    *      *            *             *
Minutes, Hours, Days, Months, Years, Weeks

Special Characters

“Represents all numbers in the range of values, such as the month fieldIt means 1 to 12 months.

“/” means every certain time interval, such as the minute field */10, which means every 10 minutes to execute once.

“-” represents a range from a certain interval, which is a closed interval. For example, “2-5” means “2,3,4,5”, and 0-23/2 in the hourly field means that it is executed every two hours in the range of 0-23 points.

“Dispersed numbers (not necessarily continuous), such as 1,2,3,4,7,9.

Note: Sunday = 0 (first day) or Sunday = 7 (last day) because the first day of the week varies from place to place.

Examples)

Execute command once a minute (because cron scans every minute by default, so it's all *)
*/1 * * * * /bin/date  >> /root/Desktop/date.txt

Execute commands at 3 and 15 minutes per hour
3,15 * * * * /bin/cp /root/Desktop/date.txt /root/date.log

Execute commands at 3 and 15 minutes every morning from 8 to 11:00:00:00:
3,15  8-11  *  *  *  command

Execute commands every two days at 8-11 a.m. in the 3rd and 15th minutes:
3,15  8-11  */2  *   *  command

Execute commands in the 3rd and 15th minutes of every Monday morning from 8am to 11am
3,15  8-11   *   *  1 command

Execute command at 21:30 per night:
30  21   *   *  * command

Record time to / home / uer01 / 2. log every 15 minutes from 6 p.m. to 6 a.m. the next day
*/15  18-23,0-6 * * * /bin/date  >> /home/user01/2.log
0,15,30,45  18-23,0-6 * * * /bin/date  -R >> /home/user01/2.log

Cloning Virtual Machine

1 Take a snapshot

Right-click Virtual Machine – > Snapshot – > Take Snapshot

2 Cloning

Cloning from snapshots

Cloning from Virtual Machines

Manage – > Clone – > Select from Snapshot (Current Status of Virtual Machine) – > Complete Clone

3. Modifying Network Card Information

The key to modifying the host name, mapping and IP address of the cloned virtual machine is to modify the network card information.

1) Modify the host name

# vi/etc/sysconfig/network # Modify host name

2) Modifying mappings

# vi/etc/hosts # Modify host mapping (linux, windows changes)

3) Modification of network card

# vi/etc/udev/rules.d/70-persistent-net.rules# network card information (mac address HWADD)

Delete the original network card information (distinguished by MAC address)

Change the name information of the new network card to eth0

Revised content

​ # PCI device 0x8086:0x100f (e1000)

​ SUBSYSTEM==”net”, ACTION==”add”, DRIVERS==”?“, ATTR{address}==”00:0c:29:b6:46:5d”, ATTR{type}==”1″, KERNEL==”eth“, NAME=”eth0”

4) modification of IP

​ # vi /etc/sysconfig/network-scripts/ifcfg-eth0

Delete uuid, modify MAC address, IPADDR, ONBOOT, BOOTPROTO

​ ONBOOT=yes

​ BOOTPROTO=static

​ HWADDR=00:0c:29:b6:46:5d

​ IPADDR=192.168.239.201

​ PREFIX=24

​ GATEWAY=192.168.239.2

​ DNS1=192.168.239.2

​ NAME=”System eth0″

# reboot restart the virtual machine (because the host name has been changed)

Recommended Today

Rethinking the Java static keyword

The Java class, while also wrote a lot of Java code, but there has been a lot of doubt, the static keyword has puzzled me for a long time, today didn’t mean to study, on zhihu check again carefully and found the best answer to the topic of https://www.zhihu.com/question/36615154 This article thoroughly understanding of the […]