linux 网络管理 实验

目录

网络管理

主机名管理

  1. 执行如下命令查看主机名。
bash 复制代码
[root@openEuler ~]# hostname
openEuler
[root@openEuler ~]# cat /etc/hostname		#这个文件是主机名的配置文件
openEuler
  1. 执行如下命令临时修改主机名。
bash 复制代码
[root@openEuler ~]# hostname huawei			#临时修改主机名,重启失效
[root@openEuler ~]# hostname
huawei
[root@openEuler ~]# bash		#重新启动一个会话
Welcome to 4.19.90-2003.4.0.0036.oe1.x86_64
System information as of time:  Thu Jul  2 11:45:09 CST 2020
System load:    0.00
Processes:      178
Memory used:    18.5%
Swap used:      0.0%
Usage On:       9%
IP address:     192.168.110.248
Users online:   2
[root@huawei ~]#		#可以看到前面的提示符里,主机名已经变成了huawei
[root@huawei ~]# exit
exit
[root@openEuler ~]#		
  1. 执行如下步骤永久修改主机名。
bash 复制代码
方法一:
[root@openEuler ~]# hostnamectl set-hostname huawei		#此种方法不需要重启,重新登录即可
bash 复制代码
方法二:
[root@openEuler ~]# vim /etc/hostname
#修改此文件中主机名,保存退出即可,需要重启才可以生效。
[root@openEuler ~]# reboot

网络管理

  1. 执行如下步骤使用IP命令修改网卡IP地址。
bash 复制代码
[root@openEuler ~]# ip addr show   #显示当前主机的IP信息
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: enp4s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 28:6e:d4:8a:2b:b6 brd ff:ff:ff:ff:ff:ff
    inet 192.168.110.247/24 brd 192.168.110.255 scope global dynamic noprefixroute enp4s0
       valid_lft 847084sec preferred_lft 847084sec
    inet6 fe80::382e:b477:10e8:f0b6/64 scope link noprefixroute
       valid_lft forever preferred_lft forever
3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
    link/ether 52:54:00:69:ec:cd brd ff:ff:ff:ff:ff:ff
    inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
       valid_lft forever preferred_lft forever
4: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc fq_codel master virbr0 state DOWN group default qlen 1000
link/ether 52:54:00:69:ec:cd brd ff:ff:ff:ff:ff:ff
bash 复制代码
[root@openEuler ~]# ip addr add 192.168.110.100/24 dev enp4s0
[root@openEuler ~]# ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: enp4s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 28:6e:d4:8a:2b:b6 brd ff:ff:ff:ff:ff:ff
    inet 192.168.110.247/24 brd 192.168.110.255 scope global dynamic noprefixroute enp4s0
       valid_lft 846990sec preferred_lft 846990sec
    inet 192.168.110.100/24 scope global secondary enp4s0
       valid_lft forever preferred_lft forever
    inet6 fe80::382e:b477:10e8:f0b6/64 scope link noprefixroute
       valid_lft forever preferred_lft forever
3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
    link/ether 52:54:00:69:ec:cd brd ff:ff:ff:ff:ff:ff
    inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
       valid_lft forever preferred_lft forever
4: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc fq_codel master virbr0 state DOWN group default qlen 1000
link/ether 52:54:00:69:ec:cd brd ff:ff:ff:ff:ff:ff
bash 复制代码
[root@openEuler ~]# ip addr del 192.168.110.100/24 dev enp4s0
[root@openEuler ~]# ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: enp4s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 28:6e:d4:8a:2b:b6 brd ff:ff:ff:ff:ff:ff
    inet 192.168.110.247/24 brd 192.168.110.255 scope global dynamic noprefixroute enp4s0
       valid_lft 846884sec preferred_lft 846884sec
    inet6 fe80::382e:b477:10e8:f0b6/64 scope link noprefixroute
       valid_lft forever preferred_lft forever
3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
    link/ether 52:54:00:69:ec:cd brd ff:ff:ff:ff:ff:ff
    inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
       valid_lft forever preferred_lft forever
4: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc fq_codel master virbr0 state DOWN group default qlen 1000
link/ether 52:54:00:69:ec:cd brd ff:ff:ff:ff:ff:ff
  1. 执行如下命令配置静态路由。
bash 复制代码
[root@openEuler ~]# ip route
default via 192.168.110.254 dev enp4s0 proto dhcp metric 100
192.168.110.0/24 dev enp4s0 proto kernel scope link src 192.168.110.247 metric 100
192.168.122.0/24 dev virbr0 proto kernel scope link src 192.168.122.1 linkdown
[root@openEuler ~]# ip route add 192.168.2.1 via 192.168.110.254 dev enp4s0
[root@openEuler ~]# ip route
default via 192.168.110.254 dev enp4s0 proto dhcp metric 100
192.168.2.1 via 192.168.110.254 dev enp4s0
192.168.110.0/24 dev enp4s0 proto kernel scope link src 192.168.110.247 metric 100
192.168.122.0/24 dev virbr0 proto kernel scope link src 192.168.122.1 linkdown
  1. 执行如下步骤通过修改ifcfg文件修改主机IP地址。
bash 复制代码
[root@openEuler ~]# cat /etc/sysconfig/network-scripts/ifcfg-enp4s0
TYPE=Ethernet				#配置文件接口类型
PROXY_METHOD=none		#代理方式
BROWSER_ONLY=no			#只浏览
BOOTPROTO=dhcp			#系统启动地址协议
DEFROUTE=yes				#默认路由
IPV4_FAILURE_FATAL=no		#是否一定要进行ipv4检查
IPV6INIT=yes					#是否执行IPv6
IPV6_AUTOCONF=yes			#IPv6自动配置
IPV6_DEFROUTE=yes			#IPv6默认路由
IPV6_FAILURE_FATAL=no		#是否一定要进行ipv6检查
IPV6_ADDR_GEN_MODE=stable-privacy		#I Pv6地址生成方式
NAME=enp4s0				#网络连接的名字
UUID=90dbef32-15b2-3400-81c7-f98ece257a55		#设备UUID
ONBOOT=yes				#随系统启动
AUTOCONNECT_PRIORITY=-999				#自动连接优先级
DEVICE=enp4s0				#物理设备的名字
bash 复制代码
###配置网络时可以将dhcp修改成static或者none,然后增加如下信息:
IPADDR=192.168.100.11
NETMASK=255.255.255.0
GATEWAY=192.168.110.254
DNS1=114.114.114.114
###如何生效
[root@openEuler ~]# ifdown enp4s0
[root@openEuler ~]# ifup enp4s0


  1. 执行如下命令修改/etc/hosts。
bash 复制代码
[root@openEuler ~]# vim /etc/hosts    #hosts是系统中一个负责IP地址与域名快速解析的文件,在最后新增一行,输入如下信息:
159.138.7.136  server			#新增这一行,完成后保存退出
[root@openEuler ~]# ping server -c 3
PING server (159.138.7.136) 56(84) bytes of data.
64 bytes from server (159.138.7.136): icmp_seq=1 ttl=40 time=53.3 ms
64 bytes from server (159.138.7.136): icmp_seq=2 ttl=40 time=51.3 ms
64 bytes from server (159.138.7.136): icmp_seq=3 ttl=40 time=52.4 ms

--- server ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2005ms
rtt min/avg/max/mdev = 51.288/52.351/53.338/0.838 ms
相关推荐
成都古河云25 分钟前
智慧场馆:安全、节能与智能化管理的未来
大数据·运维·人工智能·安全·智慧城市
算法与编程之美27 分钟前
文件的写入与读取
linux·运维·服务器
xianwu54344 分钟前
反向代理模块
linux·开发语言·网络·git
Amelio_Ming1 小时前
Permissions 0755 for ‘/etc/ssh/ssh_host_rsa_key‘ are too open.问题解决
linux·运维·ssh
心灵彼岸-诗和远方1 小时前
Devops业务价值流:软件研发最佳实践
运维·产品经理·devops
JuiceFS2 小时前
好未来:多云环境下基于 JuiceFS 建设低运维模型仓库
运维·云原生
Ven%2 小时前
centos查看硬盘资源使用情况命令大全
linux·运维·centos
萨格拉斯救世主2 小时前
戴尔R930服务器增加 Intel X710-DA2双万兆光口含模块
运维·服务器
Jtti3 小时前
Windows系统服务器怎么设置远程连接?详细步骤
运维·服务器·windows
TeYiToKu3 小时前
笔记整理—linux驱动开发部分(9)framebuffer驱动框架
linux·c语言·arm开发·驱动开发·笔记·嵌入式硬件·arm