一文学会CentOS常用操作

154 阅读4分钟

持续创作,加速成长!这是我参与「掘金日新计划 · 6 月更文挑战」的第8天,点击查看活动详情

系列文章目录

如果本文对你们的开发之路有所帮助,请帮忙点个赞,您的支持是我坚持写博客的动力

切换命令行视图 init 3

init 常见命令

命令含义
init 0停机
init 1单用户形式,只root进行维护
init 2多用户,不能使用net file system
init 3完全多用户
init 5图形化
init 6重启

本文主要介绍 init 3多用户 命令行视图

1、鼠标右键点击Open Terminal

命令行窗口

2、输入init 3切换至命令行视图

3、会提示输入密码验证,点击Authenticate

调整到命令行视图,输入账号,密码即可

修改CentOS系统为静态获取,默认为dhcp获取

1、先切换到超级管理员用户

[janyxe@localhost ~]$ su
Password:
[root@localhost janyxe]#

2、编辑网卡命令

ifcfg-ens33为CentOS默认网卡

[root@localhost janyxe]# [root@localhost janyxe]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.162.126  netmask 255.255.255.0  broadcast 192.168.162.255
        inet6 fe80::e8ba:b334:3292:5eef  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:e9:b9:08  txqueuelen 1000  (Ethernet)
        RX packets 18649  bytes 24513805 (23.3 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 6938  bytes 451178 (440.6 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 1000  (Local Loopback)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

virbr0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255
        ether 52:54:00:13:1d:e9  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

3、CentOS默认为dhcp动态获取IP

TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="dhcp"
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="0d0606e8-f3a4-41c6-b93a-3df3b1f7c160"
DEVICE="ens33"
ONBOOT="yes"

4、 ifconfig 查询当前网络信息

可看到ens33网卡通过dhcp获取到的ip

[root@localhost janyxe]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.162.126  netmask 255.255.255.0  broadcast 192.168.162.255
        inet6 fe80::e8ba:b334:3292:5eef  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:e9:b9:08  txqueuelen 1000  (Ethernet)
        RX packets 18649  bytes 24513805 (23.3 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 6938  bytes 451178 (440.6 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 1000  (Local Loopback)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

virbr0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255
        ether 52:54:00:13:1d:e9  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

5、修改ens33 网卡信息

TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="static"
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="0d0606e8-f3a4-41c6-b93a-3df3b1f7c160"
DEVICE="ens33"
ONBOOT="yes"
IPADDR=192.168.162.126  # 自定义ip地址
NETMASK=255.255.255.0   # 网段 默认为24位
GATEWAY=192.168.162.2	# 指向宿主机网卡IP
DNS1=192.168.162.2		# 指向宿主机网卡IP

wq命令保存

6、systemctl restart network 命令重启网络

[root@localhost janyxe]# systemctl restart network

7、测试外网网络

[root@localhost janyxe]# ping www.baidu.com
PING www.a.shifen.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=9.61 ms
64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=2 ttl=128 time=10.4 ms
64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=3 ttl=128 time=10.5 ms
64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=4 ttl=128 time=9.43 ms