用户管理和网络配置

                                                                                                            用户管理和网络配置

1.案例 网络的配置

主机名:server0.example.com

IP地址:172.25.0.11

子网掩码:255.255.255.0

默认网关:172.25.0.254

DNS服务器:172.25.254.254

3.2方案

使用nmcli配置网络连接时的基本操作,

查看网络连接、连接详情:

nmcli con show

nmcli con show"连接名"

修改网络连接参数:

nmcli con modify"连接名"ipv4.method auto|manual

nmcli con modify"连接名"ipv4.addresses"IP地址/掩码长度[默认网关]"ipv4.dns DNS服务器地址

nmcli con modify"连接名"connection.autoconnect yes|no

3.3步骤

实现此案例需要按照如下步骤进行。

步骤一:配置固定主机名

1)配置前,检查是否设置静态主机名

[root@server0~]#hostnamectl

Static hostname:n/a//未设置静态主机名

Transient hostname:server0.example.com

2)设置为指定的主机名

[root@server0~]#vim /etc/hostname //建立主机名配置文件

server0.example.com

3)配置后,检查结果

[root@server0~]#hostnamectl

Static hostname:server0.example.com //已设置静态主机名

Icon name:computer

....

步骤二:配置静态IP地址参数

1)查看当前主机的网卡设备、网络连接

[root@server0~]#nmcli connection show

名称UUID类型设备

System eth0 5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03 802-3-ethernet eth0

2)修改连接“System eth0”的配置

将配置方式指定为manual,指定IP地址、默认网关、DNS地址,并配置自动连接:

[root@server0~]#nmcli connection modify "System eth0" ipv4.method manual ipv4.addresses "172.25.0.11/24 172.25.0.254" ipv4.dns 172.25.254.254 connection.autoconnect yes

3)重新激活连接“System eth0

通过up指令激活连接配置,必要时也可以先downup

[root@server0~]#nmcli connection up "System eth0 "//激活连接

Connection successfully activated(D-Bus active

path:/org/freedesktop/NetworkManager/ActiveConnection/1)

确保系统服务NetworkManager开机自启:

[root@server0~]#systemctl restart NetworkManager

[root@server0~]#systemctl enable NetworkManager

4)检查修改结果,确认无误

检查IP地址:

[root@server0~]#ifconfig eth0

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

inet 172.25.0.11 netmask 255.255.255.0 broadcast 172.25.0.255

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

ether 52:54:00:00:00:0b txqueuelen 1000(Ethernet)

RX packets 1394 bytes 138855(135.6 KiB)

RX errors 0 dropped 0 overruns 0 frame 0

TX packets 944 bytes 98495(96.1 KiB)

TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

检查默认网关地址:

[root@server0~]#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 1024 0 0 eth0

172.25.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0

检查DNS服务器地址

[root@server0~]#cat  /etc/resolv.conf

#Generated by NetworkManager

search example.com

Nameserver  172.25.254.254

如果在使用nmcli修改网络连接时并未指定ipv4.dns,也可以直接修改DNS客户端配置文件/etc/resolv.conf,确保添加有上述记录即可。

步骤三:验证网络配置结果

通过ssh远程访问server0

[root@room9pc13~]#ssh -X [email protected]

Warning:Permanently added'server0.example.com'(ECDSA)to the list of known hosts.

Last login:Fri Dec 23 19:00:12 2016 from 172.25.0.250

[root@server0~]#hostname  //确认自己的主机名

server0.example.com

在虚拟机server0上,可以查询server0desktop0content等站点:

[root@server0~]#host server0.example.com

server0.example.com has address 172.25.0.11

[root@server0~]#host desktop0.example.com

desktop0.example.com has address 172.25.0.10

desktop0.example.com mail is handled by 10 smtp0.example.com.

[root@server0~]#host content.example.com

content.example.com has address 172.25.254.254


案例4:查找并处理文件

4.1问题

本例要求采用不少于两种方法完成以下任务:

找出所有用户student拥有的文件

把它们拷贝到/root/findfiles/文件夹中

4.2步骤

实现此案例需要按照如下步骤进行。

步骤一:确认能找到指定的文件

1)确认新版内核的下载地址

[root@server0~]#find / -user student-type f

find:/proc/1853/task/1853/fdinfo/6:没有那个文件或目录

find:/proc/1853/fdinfo/6:没有那个文件或目录

/var/spool/mail/student

/home/student/.bash_logout

/home/student/.bash_profile

/home/student/.bashrc

/home/student/.ssh/authorized_keys

/home/student/.config/gnome-initial-setup-done

/home/student/.config/monitors.xml

对于上述操作中出现的/proc信息忽略即可。

步骤二:处理找到的文件

1)创建目标文件夹

[root@server0~]#mkdir/root/findfiles

2)拷贝找到的文件到目标文件夹

以下两种方法任选一种:

[root@server0~]#find / -user student -type f -exec cp -p {}  /root/findfiles/ \;

....

或者

[root@server0~]#\ cp -p $(find / -user student-type f) /root/findfiles/

....

3)确认拷贝结果

[root@server0~]#ls -lh A /root/findfiles/

总用量24K

-rw-------.1 student student 1.7K 711 2014 authorized_keys

-rw-r--r--.1 student student 18 129 2014.bash_logout

-rw-r--r--.1 student student 193 129 2014.bash_profile

-rw-r--r--.1 student student 231 129 2014.bashrc

-rw-r--r--.1 student student 4 711 2014 gnome-initial-setup-done

-rw-r--r--.1 student student 1.5K 711 2014 monitors.xml

-rw-rw----.1 student mail 0 711 2014 student


案例5:查找并提取文件内容

5.1问题

本例要求在文件/usr/share/dict/words中查找到所有包含字符串seismic的行,并满足下列要求:

将找到的行按原文顺序拷贝到/root/wordlist文件中

文件/root/wordlist不要包含空行,并且其中所有行的内容必须是/usr/share/dict/words文件中原始行的准确副本

5.2步骤

实现此案例需要按照如下步骤进行。

1)使用grep命令查找指定的关键词,并通过重定向输出保存到指定的文件:

[root@serverX~]#grep 'seismic' /usr/share/dict/words > /root/wordlist

2)确认提取结果

[root@server0~]#cat /root/wordlist

anaseismic

antiseismic

aseismic

aseismicity

bradyseismic

....

猜你喜欢

转载自www.cnblogs.com/qingbai/p/11934431.html
今日推荐