Linux常用网络配置练习(1)
  hjlznhSEnpzZ 2023年11月02日 31 0

常见的软件包封装类型有哪些?各有什么特点?

文件类型

保存目录

rpm软件包

扩展名 “.rpm” rpm yum

deb软件包

扩展名为 “.deb” dpkg apt-get

源代码软件包

一般为 “.tar.gz” 、“.tar.bz2” 等格式的压缩包

包含程序的原始代码

绿色免安装的软件包

在压缩包内提供已编译好的执行程序文件

解开压缩包后的文件即可直接使用

使用rpm命令能够实现哪些较常用的RPM包管理操作?

查看软件包是否安装  # rpm -q 软件名字
查看系统中所有已经安装的软件包有哪些 # rpm -qa
统计已经安装的软件包的个数  # rpm -qa | wc -l
查询某个文件是由那个软件包安装的  # rpm -qf 文件的绝对路径
查询软件的配置文件   # rpm -qc httpd 
安装某个软件是,都安装了哪些文件  # rpm -ql setup
查询安装的软件包的信息  # rpm -qi setup

源码包编译安装的基本过程有哪几个?

确认源代码编译环境,需要gcc、make等
下载软件包
使用tar命令进行解压,解压到指定目录,一般到/usr/src目录下
查看解压路径下的./configuser脚本,用来设置安装目录、安装模块等选项
运行make命令进行编译,生产可执行二进制文件
运行make install命令进行安装,复制二进制文件到系统,配置应用环境
测试及应用、维护软件


查看自己的虚拟机IP信息,包括以下信息并将信息记录到一个文本文件

  1. IP地址及子网掩码、广播地址、MAC地址信息
  2. 主机名信息
  3. DNS服务器
[root@wei ~]# ifconfig ens33 > ttt 
[root@wei ~]# hostname >> ttt
[root@wei ~]# cat /etc/resolv.conf >> ttt

Linux常用网络配置练习(1)_IPV6

临时修改自己的IP地址为192.168.154.200/24

[root@localhost ~]# ifconfig ens33 192.168.154.200 netmask 255.255.255.0

Linux常用网络配置练习(1)_IPV6_02

永久修改自己的主机名为test-server

[root@localhost ~]# hostnamectl set-hostname test-server

添加202.106.0.20、8.8.8.8为自己的备份DNS服务器地址

[root@test-server ~]# vim /etc/resolv.conf
[root@test-server ~]# cat /etc/resolv.conf
# Generated by NetworkManager
search localdomain
nameserver 192.168.115.2
nameserver 202.106.0.20
nameserver 8.8.8.8

通过修改网卡配置文件的方式,配置以下主机网络参数:

  • 配置ip地址为192.168.100.10/24
  • 网关地址为192.168.100.254
  • DNS服务器为202.106.0.20, 备份DNS为8.8.8.8
  • 开机启动网卡
[root@test-server ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33 
[root@test-server ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens33 
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=none
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33
UUID=2f28d90f-0572-49b1-84ce-c4aff6cb84d3
DEVICE=ens33
ONBOOT=yes
IPADDR0=192.168.100.10
PREFIX0=24
GATEWAY0=192.168.100.254
DNS1=202.106.0.20
DNS2=8.8.8.8

使用nmcli显示所有连接

[root@test-server ~]# nmcli connection show
NAME    UUID                                  TYPE      DEVICE 
ens33   2f28d90f-0572-49b1-84ce-c4aff6cb84d3  ethernet  ens33  
virbr0  607928a3-b670-407f-b4a5-e984e3d4320d  bridge    virbr0

使用nmcli显示其中一个活动链接的配置设

[root@test-server ~]# nmcli connection show ens33
connection.id:                          ens33
connection.uuid:                        2f28d90f-0572-49b1-84ce-c4aff6cb84d3
connection.stable-id:                   --
connection.type:                        802-3-ethernet
connection.interface-name:              ens33
connection.autoconnect:                 是
connection.autoconnect-priority:        0
........
.....

使用nmcli查看设备状态

[root@test-server ~]# nmcli device status 
DEVICE      TYPE      STATE   CONNECTION 
ens33       ethernet  已连接  ens33      
virbr0      bridge    已连接  virbr0     
lo          loopback  未托管  --         
virbr0-nic  tun       未托管  --

使用nmcli删除现有所有链接

[root@test-server ~]# nmcli connection delete ens33 virbr0 
成功删除连接 "ens33" (2f28d90f-0572-49b1-84ce-c4aff6cb84d3)。
成功删除连接 "virbr0" (607928a3-b670-407f-b4a5-e984e3d4320d)。

使用nmcli创建一个新连接。该链接使用DHCP方式自动获取ip 地址,网关和DNS.

[root@test-server ~]# nmcli connection add con-name yu type ethernet ifname ens33 
连接 "ens33" (96629896-a1b7-4767-a41b-f9255fd86d11) 已成功添加。

使用nmcli查看新连接获得ip 地址,网关和DNS。

[root@test-server ~]# nmcli connection show ens33

Linux常用网络配置练习(1)_nmcli_03

使用nmcli将刚才的新连接改为手动设置,并将刚才通过自动获取获得的ip地址,网关和DNS改为手工配置。

[root@test-server ~]# nmcli connection modify yu ipv4.method manual ipv4.addresses 192.168.115.128/24 ipv4.gateway 192.168.115.2 ipv4.dns 192.168.115.2

确认配置,使用新配置的地址测试网络是否通信。

[root@test-server ~]# ping www.sina.com
PING spool.grid.sinaedge.com (111.62.129.51) 56(84) bytes of data.
64 bytes from 111.62.129.51 (111.62.129.51): icmp_seq=1 ttl=128 time=8.67 ms
64 bytes from 111.62.129.51 (111.62.129.51): icmp_seq=2 ttl=128 time=8.10 ms
64 bytes from 111.62.129.51 (111.62.129.51): icmp_seq=3 ttl=128 time=11.7 ms
64 bytes from 111.62.129.51 (111.62.129.51): icmp_seq=4 ttl=128 time=8.24 ms
^C
--- spool.grid.sinaedge.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3005ms
rtt min/avg/max/mdev = 8.106/9.184/11.706/1.474 ms

使用ping命令测试自己的Linux主机是否可以上网(可以选择www.baidu.com),连续ping100个包,查看其网络延迟大小

[root@test-server ~]# ping www.baidu.com -c 100
PING www.a.shifen.com (39.156.66.18) 56(84) bytes of data.
64 bytes from 39.156.66.18 (39.156.66.18): icmp_seq=1 ttl=128 time=16.9 ms
64 bytes from 39.156.66.18 (39.156.66.18): icmp_seq=2 ttl=128 time=19.3 ms
64 bytes from 39.156.66.18 (39.156.66.18): icmp_seq=3 ttl=128 time=18.9 ms
64 bytes from 39.156.66.18 (39.156.66.18): icmp_seq=4 ttl=128 time=17.1 ms
64 bytes from 39.156.66.18 (39.156.66.18): icmp_seq=5 ttl=128 time=17.2 ms
64 bytes from 39.156.66.18 (39.156.66.18): icmp_seq=6 ttl=128 time=16.7 ms
64 bytes from 39.156.66.18 (39.156.66.18): icmp_seq=7 ttl=128 time=17.5 ms
64 bytes from 39.156.66.18 (39.156.66.18): icmp_seq=8 ttl=128 time=19.0 ms
64 bytes from 39.156.66.18 (39.156.66.18): icmp_seq=9 ttl=128 time=21.6 ms
64 bytes from 39.156.66.18 (39.156.66.18): icmp_seq=10 ttl=128 time=17.1 ms
.............

使用traceroute命令测试到达www.baidu.com和www.google.com主机路径上的所有路由器地址

[root@test-server ~]# traceroute www.baidu.com
traceroute to www.baidu.com (39.156.66.14), 30 hops max, 60 byte packets
 1  gateway (192.168.115.2)  0.132 ms  0.133 ms  0.085 ms
 2  * * *
 3  * * *
.....
[root@test-server ~]# traceroute www.google.com
traceroute to www.google.com (31.13.70.20), 30 hops max, 60 byte packets
 1  gateway (192.168.115.2)  0.182 ms  0.096 ms  0.078 ms
 2  * * *
 3  * * *
.....

使用域名解析命令将自己经常访问的网站的IP地址解析出来,并记录到本地hosts文件,以便加快访问速度

[root@test-server ~]# host www.sina.com > hosts
[root@test-server ~]# host www.baidu.com >> hosts
[root@test-server ~]# cat hosts 
www.sina.com is an alias for us.sina.com.cn.
us.sina.com.cn is an alias for spool.grid.sinaedge.com.
spool.grid.sinaedge.com has address 111.62.129.51
spool.grid.sinaedge.com has IPv6 address 2409:8c04:1101:9::7:81
www.baidu.com is an alias for www.a.shifen.com.
www.a.shifen.com has address 39.156.66.14
www.a.shifen.com has address 39.156.66.18

查看自己的主机网关的MAC地址,并静态绑定,以便防局域网ARP攻击

[root@test-server ~]# arp -a
? (192.168.115.1) at 00:50:56:c0:00:08 [ether] on ens33
gateway (192.168.115.2) at 00:50:56:e3:12:92 [ether] on ens33
[root@test-server ~]# arp -s 192.168.115.2 00:50:56:e3:12:92


【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
  pfb3gDAOHucg   2023年12月11日   28   0   0 nmcliifconfig
  COAWCwhiWpsR   2023年12月10日   26   0   0 DNS
  COAWCwhiWpsR   2023年12月06日   29   0   0 DNS
  Yoru5qB4TSKM   2023年12月10日   39   0   0 服务器重启IP
  YKMEHzdP8aoh   2023年12月11日   61   0   0 DNSidePod
  48fXx4UfWSFg   2023年12月06日   54   0   0 bcIPbundle
  eHipUjOuzYYH   2023年12月06日   22   0   0 nginx加载IPV6
  aYmIB3fiUdn9   2023年12月08日   50   0   0 客户端IPNATlvs