天天看點

配置網絡

1.配置網絡目的

1.遠端登入它

2.可以使用yum安裝其他的包

1.1配置網絡步驟

1.執行dhclient指令,自動擷取ip位址(NAT模式,它可以自動生成一個ip位址)

檢視ip位址的指令ip addr

快捷鍵ctrl -L 清屏

2.配置ip位址,要知道:ip位址,子網路遮罩,網關,DNS

檢視網關指令iproute

公共的DNS:119.29.29.29 114.114.114.114 202.106.0.20 8.8.8.8

3.編輯配置檔案

按Tab鍵自動補全指令或者檔案路徑名字

vi /etc/sysconfig/network-scripts/ifcfg-ens33直接回車,進入到配置檔案裡面按i,進入編輯模式,用方向鍵把光标挪到最下面,另外一行添加如下内容

IPADDR=192.168.109.133 #自動擷取的ip位址

NETMASK=255.255.255.0 #位址

GATEWAY=192.168.109.2 #擷取的關網

DNS1=119.29.29.29 #dns

還需要更改BOOTPROTO=static和ONBOOT=yes  

擷取ip位址,檢視ip

重新開機網絡服務,ping百度

[root@localhost ~]# systemctl restart network

[root@localhost ~]# ping www.baidu.com

PING www.baidu.com (14.215.177.38) 56(84) bytes of data.

64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=1 ttl=128 time=16.7 ms

64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=2 ttl=128 time=16.5 ms

64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=3 ttl=128 time=15.6 ms

64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=4 ttl=128 time=15.8 ms

其他

cat 檢視檔案内容

如果遇到一個很長的檔案,cat之後就看不到前面的内容了,此時可以用管道和less指令結合起來檢視,管道符 | 作用是把管道左邊的指令交給管到右邊指令去處理

如:cat /etc/init.d/network | less

b 網上翻 f往下翻 q退出less

2.遠端登入

xshell 登入 遠端的linux 還有putty

Xshell個人版下載下傳

試試這個位址能否下載下傳:https://cdn.netsarang.net/0763e317/Xshell-6.0.0121p.exe

如果不行,就到官網(下面位址)下吧

https://www.netsarang.com/download/down_form.html?code=622

說明:License type 選擇"Home and school use"

putty官方下載下傳位址:

https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html

這邊選擇的是xshell,可以Windows登入linux linux登入linux mca登入linux

linux登入linux

[root@localhost ~]# ssh [email protected] //登入指令

The authenticity of host '192.168.109.133 (192.168.109.133)' can't be established.

ECDSA key fingerprint is SHA256:C3899wVB7Svy9IdEn7wPBSAbZCyrHR4nSlOQnf/thlY.

ECDSA key fingerprint is MD5:30:f1:03:ae:84:a6:f6:d7:f0:0a:dd:a2:2f:38:0a:d3.

Are you sure you want to continue connecting (yes/no)? yes

Warning: Permanently added '192.168.109.133' (ECDSA) to the list of known hosts.

[email protected]'s password: 輸入密碼

2.0秘鑰認證

使用一堆秘鑰進行驗證身份。公鑰+私鑰 公鑰是用來加密,私鑰是用來解密

點選工具找到-使用者秘鑰管理者-點選生成

保持預設

下一步

輸入秘鑰名稱-點選完成

配置網絡

點選屬性-點選公鑰一會要用到

配置網絡

想驗證那台機器就到那台機器上去配置

把公鑰放到哪裡是要講究的

[root@localhost ~]# cd ~/.ssh/ 進入目錄

[root@localhost .ssh]# vi authorized_keys 編輯配件檔案

把剛剛公鑰複制進來

ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAmljL8plyVnsd8crXSYfogx6wYtMh3Xj3fkfqgS5LiYxUsqhXYmqOZZ7zpWYHeuKBAXfd/T0gjRQJKwETC/qz0kV9mIwRrW9rDlU/oo/w4afgxTtZlrYZ5mcUpExZnmL/FuccLjkEJfySfMfybTJom85NijgCpzxnvRE6BHUzQZVF+Vo5fMfu/XxSNkLr4UtbaLubsqft8deQxpQzvkzFM+87FdJFeYo+0oMYWS9ifid6DjI/OdRNxJwROMK34qgXzyhJjQpZCqwUDKa1qk1VJ6nrjDwBnSiqc0Lc/N0dldmwMOT1X8m5PYoj1a6MgRkJ/hzAdMd5acy+l1cqQ0zYGQ== rsa 2048-082719

給檔案600權限

[root@localhost .ssh]# chmod 600 authorized_keys

回到xshell點選主機名-屬性

點選使用者身份認證-選擇Public Key-在選擇使用者秘鑰的名字-确定即可登入進linux

總結:xshell-工具-使用者秘鑰管理者-生成-密碼留白-複制公鑰

到linux機器執行

1.建立.ssh目錄 mkdir ~/.ssh

2.進入cd .ssh

3.編輯配置檔案vi authorized_keys 注:這配置檔案不能打錯

4.給檔案600權限

5.到xshell的會話屬性-使用者身份認證-選擇Public Key-在選擇使用者秘鑰的名字-确定即可登入進linux

3.0Linux密鑰認證登入Linux

到vmware

1.做一個快照 點選右鍵-找到快照-拍攝快照

2.點選右鍵-管理-克隆

如何指令關機? 執行指令 init 0 或者shutdown -h now

如何指令重新開機?執行指令init 6 或者reboot ,shutdown -r now

下一步 虛拟機中的目前狀态 連接配接克隆 填寫名稱和路徑

3.修改網卡ip

編輯vi /etc/sysconfig/network-scripts/ifcfg-ens36

修改IPADDR=的ip

找到UUID哪行前面加上#即可

更改主機名

hostnamectl set-hostname linux1

秘鑰認證

[root@linux1 ~]# ssh-keygen 生成秘鑰對

Generating public/private rsa key pair.

Enter file in which to save the key (/root/.ssh/id_rsa):

/root/.ssh/id_rsa already exists.

Overwrite (y/n)? y

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Your identification has been saved in /root/.ssh/id_rsa.

Your public key has been saved in /root/.ssh/id_rsa.pub.

The key fingerprint is:

SHA256:qk/l/cPbf5wfG2zK9g6GDZrPfR08GPuqTn/oy4eBXIM root@linux1

The key's randomart image is:

+---[RSA 2048]----+

.

E +

S ..o *

+ .oo++.+

o .o.+ +=*=

o +.O=+*B

... .=*%X==

+----[SHA256]-----+

[root@linux1 ~]# ssh-copy-id [email protected] 拷貝公鑰到那台機器上

/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"

/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed

/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys

[email protected]'s password: 輸入134ip的密碼

Number of key(s) added: 1

Now try logging into the machine, with: "ssh '[email protected]'"

and check to make sure that only the key(s) you wanted were added.

[root@linux1 ~]# ssh [email protected] 登入

Last failed login: Tue Aug 27 10:35:04 CST 2019 from 192.168.109.133 on ssh:notty

There was 1 failed login attempt since the last successful login.

Last login: Tue Aug 27 10:23:56 2019 from 192.168.109.1

[root@linux2 ~]#

5.0重置root密碼

忘記root密碼,沒辦法登入,需要重置密碼。

用的是秘鑰認證,忘記root密碼無所謂。隻要你記得秘鑰即可。

密碼和秘鑰都支援遠端登入。是不是說啟用秘鑰,密碼就失效 了.不是兩者二選一,密鑰難被破解

改密碼:root使用者執行passwd回車輸入兩次密碼即可,root更改普通使用者輸入passwd+使用者名即可 普通使用者自己更改也是passwd回車

如果忘記密碼和秘鑰認證。總之就是無法遠端登入了如何做?

單使用者

救援模式

上一篇: RHEL chkconfig
下一篇: RHEL lvm

繼續閱讀