Linux云自动化运维第六课_weixin_30819163的博客-程序员资料

技术标签: 运维  开发工具  操作系统  

Linux云自动化运维第六课

 

第九单元  openssh-server

 

一、openssh-server

 

功能:让远程主机可以通过网络访问sshd服务,开始一个安全shell

 

二、客户端连接方式

 

ssh 远程主机用户@远程主机ip   ###连接远程主机

ssh 远程主机用户@远程主机ip -X   ###调用远程主机图形工具

ssh 远程主机用户@远程主机ip command   ###直接在远程主机运行某条命令

 

eg:[[email protected] Desktop]$ ssh [email protected]    ###连接远程主机,远程主机用户@远程主机ip

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

ECDSA key fingerprint is eb:24:0e:07:96:26:b1:04:c2:37:0c:78:2d:bc:b0:08.

Are you sure you want to continue connecting (yes/no)? yes   ###首次连接,建立认证关系yes

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

[email protected]'s password:    ###输入远程主机用户密码

Last login: Sun Mar 26 21:38:42 2017 from 172.25.254.142

[[email protected] ~]$ gedit   ###登陆成功

 

(gedit:5238): Gtk-WARNING **: cannot open display:    ###无法调用远程主机图形工具

[[email protected] ~]$ exit

登出

Connection to 172.25.254.242 closed.

[[email protected] Desktop]$ ssh [email protected] -X   ###-X,调用远程主机图形工具

[email protected]'s password:

Last login: Sun Mar 26 21:46:51 2017 from 172.25.254.42

[[email protected] ~]$ gedit   ###登陆成功,远程主机图形工具调用成功

 

** (gedit:5350): WARNING **: Couldn't connect to accessibility bus: Failed to connect to socket /tmp/dbus-UKyLlmteU7: 拒绝连接

[[email protected] ~]$ exit

登出

Connection to 172.25.254.242 closed.

[[email protected] Desktop]$ ssh [email protected] touch /home/fuwu/Desktop/file{1..3}   ###直接在远程主机运行命令touch,建立文件;文件建立在远程主机fuwu用户桌面

[email protected]'s password:

[[email protected] Desktop]$ ssh [email protected] rm -fr  /home/fuwu/Desktop/file{1..3}   ###直接在远程主机运行命令rm,删除远程主机fuwu用户桌面文件

[email protected]'s password:

[[email protected] Desktop]$ ssh ro[email protected] reboot   ###直接在远程主机运行命令reboot,重启远程主机

[email protected]'s password:

Connection to 172.25.254.242 closed by remote host.

[[email protected] Desktop]$

 

[[email protected] Desktop]$ scp [email protected]:/home/fuwu/Desktop/file .   ###将远程主机fuwu用户桌面文件file复制到当前目录

[email protected]'s password:

file                                          100%    8     0.0KB/s   00:00    

[[email protected] Desktop]$ scp file [email protected]:/home/fuwu/Desktop   ###将当前目录的文件file复制到远程主机fuwu用户的桌面

[email protected]'s password:

file                                          100%    8     0.0KB/s   00:00    

[[email protected] Desktop]$

 

三、sshkey加密

 

1.生成公钥私钥

eg:[[email protected] ~]$ ssh-keygen   ###生成公钥私钥工具

Generating public/private rsa key pair.

Enter file in which to save the key (/home/fuwu/.ssh/id_rsa):    ###加密字符保存文件(回车键,默认)

Created directory '/home/fuwu/.ssh'.

Enter passphrase (empty for no passphrase):    ###密钥密码,>4个字符(回车键也可)

Enter same passphrase again:    ###确认密码

Your identification has been saved in /home/fuwu/.ssh/id_rsa.   ###私钥路径

Your public key has been saved in /home/fuwu/.ssh/id_rsa.pub.   ###公钥路径

The key fingerprint is:

95:55:ed:da:28:22:4a:1c:fb:f6:84:e8:d6:55:0e:54 [email protected]

The key's randomart image is:

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

|           .E... |

|          .o    .|

|         .o    . |

|      .  .. .   .|

|     . oS  +   + |

|      +...o o o .|

|     ..+.o.. .   |

|     .o +.       |

|     ... ..      |

+-----------------+

[[email protected] ~]$ ls .ssh/

id_rsa  id_rsa.pub

id_rsa   ###私钥,就是钥匙

id_rsa.pub   ###公钥,就是锁

 

2.添加key认证方式

[[email protected] ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub  [email protected]

ssh-copy-id   ###添加key认证方式的工具

-i   ###指定加密key文件

/root/.ssh/id_rsa.pub   ###加密key

root   ###加密用户为root

172.25.0.11   ###被加密主机ip

eg:[[email protected] ~]$ ssh-copy-id -i /home/fuwu/.ssh/id_rsa.pub [email protected]

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

ECDSA key fingerprint is eb:24:0e:07:96:26:b1:04:c2:37:0c:78:2d:bc:b0:08.

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

/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:

 

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.

 

[[email protected] ~]$ ls .ssh/

authorized_keys  id_rsa  id_rsa.pub  known_hosts

 

3.分发钥匙给client主机

eg:[[email protected] ~]$ su -

Password:

Last login: Sun Mar 26 21:23:11 EDT 2017 on :0

[[email protected] ~]# vim /etc/ssh/sshd_config   ###进入编辑状态,79 PasswordAuthentication yes,yes改为no

[[email protected] ~]# systemctl restart sshd.service

[[email protected] ~]# exit

logout

[[email protected] ~]$ scp /home/fuwu/.ssh/id_rsa kio[email protected]:/home/kiosk/.ssh/   ###分发钥匙给主机kiosk用户

id_rsa                                        100% 1675     1.6KB/s   00:00    

[[email protected] ~]$

 

4.测试

[[email protected] ~]$ ssh [email protected]   ###通过钥匙打开,不需要密码

Last login: Sun Mar 26 22:04:38 2017

[[email protected] ~]$   

 

eg:[[email protected] ~]$ rm -fr .ssh/authorized_keys    ###删除authorized_keys

[[email protected] ~]$ ssh [email protected]    ###远程连接失败

Permission denied (publickey,gssapi-keyex,gssapi-with-mic).

[[email protected] ~]$ cp .ssh/id_rsa.pub .ssh/authorized_keys   ###复制id_rsa.pub到authorized_keys

[[email protected] ~]$ ls .ssh/

authorized_keys  id_rsa  id_rsa.pub  known_hosts

[kios[email protected] ~]$ ssh [email protected]   ###远程连接成功

Last login: Sun Mar 26 23:00:47 2017 from 172.25.254.42

 

四、提升openssh的安全级别

 

1.openssh-server配置文件

[[email protected] ~]# vim /etc/ssh/sshd_config    ###进入编辑状态

78 PasswordAuthentication yes|no   ###是否开启用户密码认证,yes为支持no为关闭

48 PermitRootLogin yes|no   ###是否允许超级用户登陆

49 AllowUsers student westos   ###用户白名单,只有在名单中出现的用户可以使用sshd建立shell

50 DenyUsers westos   ###用户黑名单

 

eg:[[email protected] ~]# vim /etc/ssh/sshd_config   ###进入编辑状态,48 PermitRootLogin no,不允许超级用户登陆

[[email protected] ~]# systemctl restart sshd.service

[[email protected] ~]$ ssh [email protected]   ###密码正确输入三次,超级用户无法登录

[email protected]'s password:

Permission denied, please try again.

[email protected]'s password:

Permission denied, please try again.

[email protected]'s password:

Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).

[[email protected] ~]# vim /etc/ssh/sshd_config   ###进入编辑状态,50 Denyusers student,用户黑名单,不允许student用户登陆

[[email protected] ~]# systemctl restart sshd.service

[[email protected] ~]$ ssh [email protected]   ###密码正确输入三次,student用户无法登录

[email protected]'s password:

Permission denied, please try again.

[email protected]'s password:

Permission denied, please try again.

[email protected]'s password:

Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).

[[email protected] ~]$ ssh [email protected]   ###fuwu用户没加入黑名单,可以登陆

[email protected]'s password:

Last login: Sun Mar 26 23:42:15 2017 from 172.25.254.42

[[email protected] ~]$ exit

登出

Connection to 172.25.254.242 closed.

[[email protected] ~]# vim /etc/ssh/sshd_config   ###进入编辑状态,49 Allowusers student,用户白名单,只允许登陆student用户

[[email protected] ~]# systemctl restart sshd.service

[[email protected] ~]$ ssh [email protected]    ###student用户在白名单上,可以登陆

[email protected]'s password:

Last failed login: Sun Mar 26 23:46:33 EDT 2017 from 172.25.254.42 on ssh:notty

There were 3 failed login attempts since the last successful login.

[[email protected] ~]$ exit

登出

Connection to 172.25.254.242 closed.

[[email protected] ~]$ ssh [email protected]   ###fuwu用户不在白名单上,无法登陆

[email protected]'s password:

Permission denied, please try again.

[email protected]'s password:

Permission denied, please try again.

[email protected]'s password:

Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).

[[email protected] ~]$

 

 

 

 

第十二单元  不同系统之间的文件传输

 

一、文件归档

1.文件归档,就是把多个文件变成一个归档文件

 

2.tar c ###创建

      f ###指定归档文件名称

      t ###显示归档文件中的内容

      r ###向归档文件中添加文件

      --get ###取出单个文件

      --delete ###删除单个文件

      x ###取出归档文件中的所有内容

      -C ###指定解档目录

      -z ###gz格式压缩

      -j ###bz2格式压缩

      -J ###xz格式压缩

eg:[[email protected] Desktop]# ls -ld dir/

drwxr-xr-x. 5 root root 4096 Mar 27 21:36 dir/

[[email protected] Desktop]# tar cf dir.tar dir/   ###打包dir,指定归档文件名dir.tar

[[email protected] Desktop]# ls

dir  dir.tar  etc.tar

[[email protected] Desktop]# du -sh dir/

4.0K dir/

[[email protected] Desktop]# du -sh dir.tar    ###查看归档文件大小

12K dir.tar

[[email protected] Desktop]# tar tf dir.tar    ###显示归档文件中的内容

dir/

dir/class1

dir/class2

dir/file1

dir/file2

dir/dir1/

dir/dir1/wenjian

dir/dir2/

dir/dir2/wenjian2

[[email protected] Desktop]# ls

dir  dir.tar  etc.tar  file

[[email protected] Desktop]# tar rf dir.tar file    ###向归档文件中添加file文件

[[email protected] Desktop]# tar tf dir.tar

dir/

dir/class1

dir/class2

dir/file1

dir/file2

dir/dir1/

dir/dir1/wenjian

dir/dir2/

dir/dir2/wenjian2

file

[[email protected] Desktop]# rm -fr file

[[email protected] Desktop]# ls

dir  dir.tar  etc.tar

[[email protected] Desktop]# tar f dir.tar --get file   ###取出归档文件中单个文件

[[email protected] Desktop]# ls

dir  dir.tar  etc.tar  file

[[email protected] Desktop]# tar f dir.tar --delete file    ###删除归档文件中单个文件

[[email protected] Desktop]# tar tf dir.tar

dir/

dir/class1

dir/class2

dir/file1

dir/file2

dir/dir1/

dir/dir1/wenjian

dir/dir2/

dir/dir2/wenjian2

[[email protected] Desktop]# ls

dir.tar  etc.tar  file

[[email protected] Desktop]# tar xf dir.tar    ###取出归档文件中所有内容

[[email protected] Desktop]# ls

dir  dir.tar  etc.tar  file

[[email protected] Desktop]# ls /mnt/

[[email protected] Desktop]# tar xf dir.tar -C /mnt/    ###指定解档目录为/mnt/

[[email protected] Desktop]# ls /mnt/

dir

 

二、压缩

 

1.gz

gzip etc.tar ###压缩成gz格式

gunzip  etc.tar.gz ###解压gz格式压缩包

tar zcf etc.tar.gz /etc ###把文件归档为tar并压缩成gz

tar zxf etc.tar.gz ###解压并解档gz格式压缩包

eg:[[email protected] Desktop]# ls

dir  etc  etc.tar

[[email protected] Desktop]# du -sh etc   ###查看目录etc的大小

34M etc

[[email protected] Desktop]# du -sh etc.tar   ###查看归档文件etc.tar的大小

30M etc.tar

[[email protected] Desktop]# gzip etc.tar    ###将etc.tar压缩成gz格式

[[email protected] Desktop]# ls

dir  etc  etc.tar.gz

[[email protected] Desktop]# du -sh etc.tar.gz    ###压缩后变小

8.4M etc.tar.gz

[ro[email protected] Desktop]# gunzip etc.tar.gz    ###解压

[[email protected] Desktop]# ls

dir  etc  etc.tar

[[email protected] Desktop]# rm -fr etc.tar

[[email protected] Desktop]# ls

dir  etc

[[email protected] Desktop]# tar zcf etc.tar.gz etc   ###把文件归档为tar并压缩成gz

[[email protected] Desktop]# ls

dir  etc  etc.tar.gz

[[email protected] Desktop]# rm -fr etc

[[email protected] Desktop]# ls

dir  etc.tar.gz

[[email protected] Desktop]# tar zxf etc.tar.gz   ###解压并解档gz格式压缩包

[[email protected] Desktop]# ls

dir  etc  etc.tar.gz

 

2.bz2

bzip2 etc.tar ###压缩成bz2格式

bunzip2 etc.tar.bz2 ###解压bz2格式压缩包

tar jcf etc.tar.bz2 /etc ###把文件归档为tar并压缩成bz2

tar jxf etc.tar.bz2  ###解压并解档bz2格式压缩包

eg:[[email protected] Desktop]# ls

dir  etc  etc.tar

[[email protected] Desktop]# bzip2 etc.tar ###压缩成bz2格式  

[[email protected] Desktop]# ls

dir  etc  etc.tar.bz2

[[email protected] Desktop]# du -sh etc.tar.bz2   ###变小

7.0M etc.tar.bz2

[[email protected] Desktop]# rm -fr etc

[[email protected] Desktop]# ls

dir  etc.tar.bz2

[[email protected] Desktop]# bunzip2 etc.tar.bz2  ###解压bz2格式压缩包

[[email protected] Desktop]# ls

dir  etc.tar

[[email protected] Desktop]# tar xf etc.tar

[[email protected] Desktop]# ls

dir  etc  etc.tar

[[email protected] Desktop]# rm -fr etc.tar

您在 /var/spool/mail/root 中有邮件

[[email protected] Desktop]# ls

dir  etc

[[email protected] Desktop]# tar jcf etc.tar.bz2 etc   ###把文件归档为tar并压缩成bz2

[[email protected] Desktop]# ls

dir  etc  etc.tar.bz2

[[email protected] Desktop]# rm -fr etc

[[email protected] Desktop]# ls

dir  etc.tar.bz2

[[email protected] Desktop]# tar jxf etc.tar.bz2     ###解压并解档bz2格式压缩包

[[email protected] Desktop]# ls

dir  etc  etc.tar.bz2

 

3.xz

xz etc.tar ###压缩成xz格式

unxz  etc.tar.xz ###解压xz格式压缩包

tar Jcf etc.tar.xz /etc ###把文件归档为tar并压缩成xz

tar Jxf etc.tar.xz ###解压并解档xz格式压缩包

eg:[[email protected] Desktop]# ls

dir  etc  etc.tar

[[email protected] Desktop]# xz etc.tar   ###压缩成xz格式

[[email protected] Desktop]# ls

dir  etc  etc.tar.xz

[[email protected] Desktop]# du -sh etc.tar.xz   ###变小

5.7M etc.tar.xz

[[email protected] Desktop]# rm -fr etc

[[email protected] Desktop]# ls

dir  etc.tar.xz

[[email protected] Desktop]# unxz etc.tar.xz    ###解压xz格式压缩包

[[email protected] Desktop]# ls

dir  etc.tar

[[email protected] Desktop]# tar xf etc.tar

[[email protected] Desktop]# rm -fr etc.tar

[[email protected] Desktop]# ls

dir  etc

[[email protected] Desktop]# tar Jcf etc.tar.xz etc   ###把文件归档为tar并压缩成xz

[[email protected] Desktop]# ls

dir  etc  etc.tar.xz

[[email protected] Desktop]# rm -fr etc

[[email protected] Desktop]# ls

dir  etc.tar.xz

[[email protected] Desktop]# tar Jxf etc.tar.xz     ###解压并解档xz格式压缩包

[[email protected] Desktop]# ls

dir  etc  etc.tar.xz

 

4.zip

zip -r etc.tar.zip etc.tar ###压缩成zip格式

unzip etc.tar.zip ###解压

eg;[[email protected] Desktop]# ls

dir  etc  etc.tar

[[email protected] Desktop]# zip -r etc.tar.zip etc.tar   ###压缩成zip格式

  adding: etc.tar (deflated 72%)

[[email protected] Desktop]# ls

dir  etc  etc.tar  etc.tar.zip

[roo[email protected] Desktop]# du -sh etc.tar.zip    ###变小

16M etc.tar.zip

[[email protected] Desktop]# rm -fr etc.tar etc

[[email protected] Desktop]# ls

dir  etc.tar.zip

[[email protected] Desktop]# unzip etc.tar.zip  ###解压

Archive:  etc.tar.zip

  inflating: etc.tar                 

[[email protected] Desktop]# ls

dir  etc.tar  etc.tar.zip

 

三、系统中的文件传输

 

scp file [email protected]:/dir ###上传,速度慢

scp [email protected]:/dir/file  /dir ###下载,速度慢

rsync [参数] file [email protected]:/dir   ###速度快

rsync -r ###同步目录

-l ###不忽略链接

-p ###不忽略文件权限

-t ###不忽文件时间戳

-g ###不忽文件所有组

-o ###不忽文件所有人

-D ###不忽略设备文件

eg:[[email protected] Desktop]# scp dir/adjtime [email protected]:/home/kiosk/Desktop/dir/

[email protected]'s password:

adjtime                                       100%   16     0.0KB/s   00:00    

[[email protected] Desktop]# scp [email protected]:/home/kiosk/Desktop/dir/adjtime .

[email protected]'s password:

adjtime                                       100%   16     0.0KB/s   00:00    

[[email protected] Desktop]$ ls -l adjtime

-rw-r--r-- 1 kiosk kiosk 18 Mar 20 00:45 adjtime

[[email protected] Desktop]$ rsync -r adjtime [email protected]:/root/Desktop/ ###同步目录

[email protected]'s password:

[[email protected] Desktop]# ls -l adjtime

-rw-r--r--. 1 root root 18 Mar 28 11:01 adjtime

[[email protected] Desktop]$ rsync -tr adjtime [email protected]:/root/Desktop/  ###不忽文件时间戳

[email protected]'s password:

[[email protected] Desktop]# ls -l adjtime

-rw-r--r--. 1 root root 18 Mar 19 12:45 adjtime

[[email protected] Desktop]$ rsync -gr adjtime [email protected]:/root/Desktop/   ###不忽文件所有组

[email protected]'s password:

[[email protected] Desktop]# ls -l adjtime

-rw-r--r--. 1 root student 18 Mar 28 11:03 adjtime

[[email protected] Desktop]$ rsync -or adjtime [email protected]:/root/Desktop/   ###不忽文件所有人

[email protected]'s password:

[[email protected] Desktop]# ls -l adjtime

-rw-r--r--. 1 student root 18 Mar 28 11:04 adjtime

 

第十一单元  管理网络

 

一、ip基础知识(ipv4)

 

2进制32位-----10进制

172.25.0.10/255.255.255.0

172.25.0.10:ip地址

255.255.255.0:子网掩码

子网掩码255位对应的ip位为网络位

子网掩码0对应的ip位为主机位

 

二、配置ip

 

1.图形化界面

nm-connection-editor

 

2.文本化图形

nmtui

 

<<命令>>

ifconfig 网卡 ip netmask ##临时设定

nmcli connection add ethernet con-name westos ifname eth0 autoconnect yes

nmcli connection add type ethernet con-name westos ifname eth0 ip4 ip/24

nmcli connection delete westos

nmcli connection show

nmcli connection down westos

nmcli connection up westos

nmcli connection modify "westos" ipv4.addresses newip/24

nmcli connection modify "westos" ipv4.method <auto|manual>

nmcli device connect eth0

nmcli device disconnect eth0

nmcli device show

nmcli device status

eg:[[email protected] Desktop]# nmcli connection add type ethernet con-name westos ifname eth0 autoconnect yes   ###网络服务开启时自动激活

Connection 'westos' (55e75ad1-f03b-4388-b5d3-bd564ec6431d) successfully added.

[[email protected] Desktop]# nmcli connection delete westos    ###删除网络

[[email protected] Desktop]# nmcli device connect eth0

Error: Device activation failed: The device has no connections available.

[[email protected] Desktop]# nmcli connection add type ethernet con-name westos ifname eth0 ip4 172.25.254.142/24

Connection 'westos' (9ff61eec-d85a-4a31-abd1-c7b40b5e623b) successfully added.

[[email protected] Desktop]# nmcli device connect eth0 Device 'eth0' successfully activated with '9ff61eec-d85a-4a31-abd1-c7b40b5e623b'.

[[email protected] Desktop]# nmcli connection show

NAME    UUID                                  TYPE            DEVICE

westos  9ff61eec-d85a-4a31-abd1-c7b40b5e623b  802-3-ethernet  eth0   

[[email protected] Desktop]# nmcli connection down westos

[[email protected] Desktop]# nmcli connection show

NAME    UUID                                  TYPE            DEVICE

westos  9ff61eec-d85a-4a31-abd1-c7b40b5e623b  802-3-ethernet  --     

[[email protected] Desktop]# nmcli connection up westos

Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/11)

[[email protected] Desktop]# nmcli connection show

NAME    UUID                                  TYPE            DEVICE

westos  9ff61eec-d85a-4a31-abd1-c7b40b5e623b  802-3-ethernet  eth0   

[[email protected] Desktop]# nmcli connection modify "westos" ipv4.addresses 172.25.254.242/24

[[email protected] Desktop]# systemctl restart network

[[email protected] Desktop]# ifconfig

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

        inet 172.25.254.242  netmask 255.255.255.0  broadcast 172.25.254.255

        inet6 fe80::5054:ff:fe00:2a0a  prefixlen 64  scopeid 0x20<link>

        ether 52:54:00:00:2a:0a  txqueuelen 1000  (Ethernet)

        RX packets 49300  bytes 3266084 (3.1 MiB)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 9112  bytes 790252 (771.7 KiB)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

 

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536

        inet 127.0.0.1  netmask 255.0.0.0

        inet6 ::1  prefixlen 128  scopeid 0x10<host>

        loop  txqueuelen 0  (Local Loopback)

        RX packets 3822  bytes 435530 (425.3 KiB)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 3822  bytes 435530 (425.3 KiB)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

 

[[email protected] Desktop]# nmcli device disconnect eth0

[[email protected] Desktop]# nmcli device show

GENERAL.DEVICE:                         eth0

GENERAL.TYPE:                           ethernet

GENERAL.HWADDR:                         52:54:00:00:2A:0A

GENERAL.MTU:                            1500

GENERAL.STATE:                          30 (disconnected)

GENERAL.CONNECTION:                     --

GENERAL.CON-PATH:                       --

WIRED-PROPERTIES.CARRIER:               on

 

GENERAL.DEVICE:                         lo

GENERAL.TYPE:                           loopback

GENERAL.HWADDR:                         00:00:00:00:00:00

GENERAL.MTU:                            65536

GENERAL.STATE:                          10 (unmanaged)

GENERAL.CONNECTION:                     --

GENERAL.CON-PATH:                       --

IP4.ADDRESS[1]:                         ip = 127.0.0.1/8, gw = 0.0.0.0

IP6.ADDRESS[1]:                         ip = ::1/128, gw = ::

[[email protected] Desktop]# nmcli device connect eth0

Device 'eth0' successfully activated with '9ff61eec-d85a-4a31-abd1-c7b40b5e623b'.

[[email protected] Desktop]# nmcli device show

GENERAL.DEVICE:                         eth0

GENERAL.TYPE:                           ethernet

GENERAL.HWADDR:                         52:54:00:00:2A:0A

GENERAL.MTU:                            1500

GENERAL.STATE:                          100 (connected)

GENERAL.CONNECTION:                     westos

GENERAL.CON-PATH:                       /org/freedesktop/NetworkManager/ActiveConnection/13

WIRED-PROPERTIES.CARRIER:               on

IP4.ADDRESS[1]:                         ip = 172.25.254.242/24, gw = 0.0.0.0

IP6.ADDRESS[1]:                         ip = fe80::5054:ff:fe00:2a0a/64, gw = ::

 

GENERAL.DEVICE:                         lo

GENERAL.TYPE:                           loopback

GENERAL.HWADDR:                         00:00:00:00:00:00

GENERAL.MTU:                            65536

GENERAL.STATE:                          10 (unmanaged)

GENERAL.CONNECTION:                     --

GENERAL.CON-PATH:                       --

IP4.ADDRESS[1]:                         ip = 127.0.0.1/8, gw = 0.0.0.0

IP6.ADDRESS[1]:                         ip = ::1/128, gw = ::

[[email protected] Desktop]# nmcli device status

DEVICE  TYPE      STATE      CONNECTION

eth0    ethernet  connected  westos     

lo      loopback  unmanaged  --         

 

<<文件>>

dhcp ###动态获取

vim /etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=eth0 ###接口使用设备

BOOTPROTO=dhcp ###网卡工作模式

ONBOOT=yes ###网络服务开启时自动激活

NAME=eth0 ###网络接口名称

wq

systemctl restart network

 

static|none ###静态网络

vim /etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=eth0  ###设备

BOOTPROTO=static|none  ###设备工作方式

ONBOOT=yes  ###开启网络服务激活设备

NAME=eth0  ##3网络接口名称

IPADDR=172.25.0.100   ###IP

NETNASK=255.255.255.0 | PREFIX=24 ###子网掩码

 

三、gateway 网关

 

1.路由器

主要功能是用来作nat的

dnat 目的地地址转换

snat 源地址转换

 

2.网关

路由器上和自己处在同一个网段的那个ip

 

3.设定网关

systemctl stop NetwrokManager

vim /etc/sysconfig/network ###全局网关

GATEWAY=网关ip

vim /etc/sysconfig/network-scripts/ifcfg-网卡配置文件 ##网卡接口网关

GATEWAY=网关ip

systemctl restart netwrok

route -n ###查询网关

Kernel IP routing table

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface

0.0.0.0   (网关)172.25.0.254    0.0.0.0         UG    0      0        0 eth0

172.25.0.0      0.0.0.0         255.255.255.0   U     0      0        0 eth0

 

 

四、dns

 

1.dns

dns是一台服务器

这太服务器提供了回答客户主机名和ip对应关系的功能

 

2.设定dns

vim /etc/resolv.conf

nameserver dns服务器ip

vim /etc/sysconfig/network-scripts/ifcfg-网卡配置文件

DNS1=dns服务器ip

 

3.本地解析文件

vim /etc/hosts

ip 主机名称

 

4.本地解析文件和dns读取的优先级调整

/etc/nsswitch.conf

 38 #hosts:     db files nisplus nis dns

 39 hosts:      files dns ##files代表本地解析文件,dns代表dns服务器,那个在前面那个优先

 

5.dhcp服务的配置

 

 

unit6-作业

 

1.在server主机中把/etc目录打包压缩到/mnt中,名字为etc.tar.gz

[[email protected] Desktop]# tar zcf /mnt/etc.tar.gz /etc

tar: Removing leading `/' from member names

 

2.复制server主机中的etc.tar.gz到desktop主机的/mnt中

[[email protected] Desktop]# scp /mnt/etc.tar.gz [email protected]:/mnt/

[email protected]'s password:

etc.tar.gz                                    100% 8537KB   8.3MB/s   00:00

 

3.同步server中的/etc中的所有文件到desktop主机中的/mnt中,包含链接文件

[r[email protected] Desktop]# rsync -lr /etc [email protected]:/mnt/

[email protected]'s password:

 

4.在系统中创建set-ip-tool命令要求如下:当在系统中执行set-ip-tool 172.25.254.x后

*)会自动显示ifconfig命令的输出

*)系统ip被设定为:172.25.254.x

[[email protected] Desktop]# vim /etc/sysconfig/network-scripts/ifcfg-eth0

[[email protected] Desktop]# systemctl restart network

#vim编辑内容:

DEVICE=eth0

BOOTPROTO=static

ONBOOT=yes

NAME=eth0

IPADDR=172.25.254.242

NETNASK=255.255.255.0

*)系统网关被设定为:172.25.254.250

[[email protected] Desktop]# vim /etc/sysconfig/network

#vim编辑内容:GATEWAY=172.25.254.250

[[email protected] Desktop]# vim /etc/sysconfig/network-scripts/ifcfg-eth0

#vim编辑内容:GATEWAY=172.25.254.250

[[email protected] Desktop]# systemctl restart network

*)系统dns被设定为:172.25.254.250

[[email protected] Desktop]# vim /etc/resolv.conf

#vim编辑内容:nameserver 172.25.254.250

[[email protected] Desktop]# vim /etc/sysconfig/network-scripts/ifcfg-eth0

#vim编辑内容:DNS1=172.25.254.250

转载于:https://www.cnblogs.com/Virgo-sept/p/6636607.html

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/weixin_30819163/article/details/99025702

智能推荐

Beta版:产品(驱动、BIOS)发布之前的测试版本,也叫做β版,与此对应的还有α版(Alpha版)。α版通常是软件开发商内部自行测试的版本,而β版则是公开发布让用户来进行测试的版本。_wenzhoufeng的博客-程序员资料

Beta版:产品(驱动、BIOS)发布之前的测试版本,也叫做β版,与此对应的还有α版(Alpha版)。α版通常是软件开发商内部自行测试的版本,而β版则是公开发布让用户来进行测试的版本。 版本号里面的Build说明这个版本是第几次编译的结果,比如: V1.79Build210比V1.79Build200的版本要新,因为V1.79Build210是"电子文档处理器"第210次编译的版本。 Alpha:

【Docker系列】容器快速上手_快速上手容器开发_小叶柏杉的博客-程序员资料

Docker CLI 命令行介绍Docker VersionWindows (Intel芯片)Server 的 OS/Arch: linux/amd64是因为Windows内置的hyper-V或者wsl2的虚拟机,是搭载的Linux系统,把docker的服务端放到了虚拟机中。$ docker versionClient: Docker Engine - CommunityCloud integration: 1.0.12Version: 20.10.5API vers

1>libcmt.lib(invarg.obj) : error LNK2005: __initp_misc_invarg 已经在 libcmtd.lib(invarg.obj) 中定义 1>li_清水迎朝阳的博客-程序员资料

1>libcmt.lib(invarg.obj) : error LNK2005: __initp_misc_invarg 已经在 libcmtd.lib(invarg.obj) 中定义1>libcmt.lib(invarg.obj) : error LNK2005: __call_reportfault 已经在 libcmtd.lib(invarg.obj) 中定义 转化

随便推点

java反序列化字节转字符串工具--SerializationDumper-v1.12_字节反序列化成字符串_qq_40624810的博客-程序员资料

下载地址:https://github.com/NickstaDB/SerializationDumper一段数据如果以aced开头,那么他就是这一段java序列化的16进制用法 :java -jar SerializationDumper-v1.1.jar aced000573720026636e2e656d61792e...

API 23 inputmethodservice.KeyboardView——属性分析_沈夜大祭司的博客-程序员资料

参阅:http://android.xsoftlab.net/reference/android/inputmethodservice/KeyboardView.html public classKeyboardViewextends Viewimplements View.OnClickListenerAdded in API level3

计算机原理考研题库,2021年计算机组成原理考研题库_世异的博客-程序员资料

**部分 名校考研真题一、选择题1.计算机硬件能够直接执行的是(  )。[2015年联考真题]Ⅰ.机器语言程序Ⅱ.汇编语言程序Ⅲ.硬件描述语言程序A.仅ⅠB.仅ⅠⅡC.仅ⅠⅢD.ⅠⅡⅢ【答案】A【解析】机器语言是计算机**可以直接执行的语言。汇编语言属于低级语言,但其源程序必须要翻译成目标程序成为机器语言程序后才能被直接执行。硬件描述语言是电子系统硬件行为描述、结构描述、数据流描述的语言。...

数据库学习笔记【MySQL】_mysql decision关键字_vx-Yang_Gaige的博客-程序员资料

一、数据库基础1、为什么要使用数据库持久化(persistence):把数据保存到可掉电式存储设备中以供之后使用。持久化的大多数时候是将内存中的数据存储在数据库中,当然也可以存储在磁盘文件、XML数据文件中。方便管理数据(例如:快速的检索等)2、什么是数据库DB:数据库(Database)即存储数据的“仓库”。它保存了一系列有组织的数据。DBMS:数据库管理系统(Dat...

Servlet概要配置_无风不起浪起浪又怎样的博客-程序员资料

1 servlet继承于HttpServlet 简单使用如下: 2 代码  Japackage com.test.action;    import java.io.IOException;  import java.io.PrintWriter;    import javax.servlet.ServletException;  import jav

kubernetes集群实战——网络插件flannel和calico应用于跨主机调度通信_Li_barroco的博客-程序员资料

1. Flannel 跨主机通信解决上篇博客在访问时的跨节点流量卡顿问题承接上篇博客的公有ip172.25.12.100配置1.1 host-gw模式cp /home/kubeadm/kube-flannel.yml . ##将flannel.yml pod清单复制到当前目录下kubectl delete -f kube-flannel.yml ##删除之前应用的flannel网络插件vim kube-flannel.yml ##编辑kube-flannel.yml文件,将网络类型改为直接路由模

推荐文章

热门文章

相关标签