网卡配置详解,修改主机名、查看系统ip、系统时间、重启和开关机

网卡配置及解释

#打开网卡配置文件
vim /etc/sysconfig/network-scripts/ifcfg-eht0
TYPE=Ethernet    # 网卡类型:为以太网
PROXY_METHOD=none    # 代理方式:关闭状态
BROWSER_ONLY=no      # 只是浏览器:否
BOOTPROTO=dhcp  #设置网卡获得ip地址的方式,可能的选项为static(静态),dhcp(dhcp协议)或bootp(bootp协议).
DEFROUTE=yes        # 默认路由:是, 不明白的可以百度关键词 `默认路由`
IPV4_FAILURE_FATAL=no     # 是不开启IPV4致命错误检测:否
IPV6INIT=yes         # IPV6是否自动初始化: 是[不会有任何影响, 现在还没用到IPV6]
IPV6_AUTOCONF=yes    # IPV6是否自动配置:是[不会有任何影响, 现在还没用到IPV6]
IPV6_DEFROUTE=yes     # IPV6是否可以为默认路由:是[不会有任何影响, 现在还没用到IPV6]
IPV6_FAILURE_FATAL=no     # 是不开启IPV6致命错误检测:否
IPV6_ADDR_GEN_MODE=stable-privacy   # IPV6地址生成模型:stable-privacy [这只一种生成IPV6的策略]
NAME=eth0     # 网卡物理设备名称  
UUID=8c75c2ba-d363-46d7-9a17-6719934267b7   # 通用唯一识别码,没事不要动它,否则你会后悔的。。
DEVICE=eth0   # 网卡设备名称, 必须和 `NAME` 值一样
ONBOOT=no #系统启动时是否设置此网络接口,设置为yes时,系统启动时激活此设备 
IPADDR=192.168.15.31   #网卡对应的ip地址
PREFIX=24             # 子网 24就是255.255.255.0
GATEWAY=192.168.15.1    #网关

修改主机名

# 方式一:
[root@local-work ~]# hostnamectl set-hostname local-work
# 需要重新登录或者执行一个解析器
[root@local-work ~]#bash

# 方式二:
[root@local-work ~]# echo "string" > /etc/hostname 
[root@local-work ~]# cat /etc/hostname
string
# 直接修改文件,不会立即生效,需要重启。

查看系统IP

# 方式一:
[root@string ~]# ip a
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:20:7e:96 brd ff:ff:ff:ff:ff:ff
    inet 192.168.15.100/24 brd 192.168.15.255 scope global noprefixroute eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::962c:f186:8d31:5eec/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever

# 方式二:
[root@string ~]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.15.100  netmask 255.255.255.0  broadcast 192.168.15.255
        inet6 fe80::962c:f186:8d31:5eec  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:20:7e:96  txqueuelen 1000  (Ethernet)
        RX packets 119  bytes 11208 (10.9 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 102  bytes 14496 (14.1 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

# 查看某一个网卡的信息
[root@string ~]# ifconfig eth0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.15.100  netmask 255.255.255.0  broadcast 192.168.15.255
        inet6 fe80::962c:f186:8d31:5eec  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:20:7e:96  txqueuelen 1000  (Ethernet)
        RX packets 119  bytes 11208 (10.9 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 102  bytes 14496 (14.1 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

系统时间

[root@string ~]# date
Fri Mar  5 09:50:27 CST 2021
[root@string ~]# date +%Y-%m-%d
2021-03-05

# 格式化时间
[root@string ~]# # 09:58:30
[root@string ~]# date +%H:%M:%S
10:01:44
[root@string ~]# date +%Y-%m-%d_%H:%M:%S
2021-03-05_10:02:05

# 设置时间
[root@string ~]# date -s "2029-03-05 10:02:44"
Mon Mar  5 10:02:44 CST 2029
[root@string ~]# date +%Y-%m-%d_%H:%M:%S
2029-03-05_10:03:03

# 同步互联网时间
[root@string ~]# yum install -y ntpdate
[root@string ~]# ntpdate ntp.aliyun.com

# 系统硬件时钟
[root@string ~]# hwclock -r
Fri 05 Mar 2021 10:10:40 AM CST  -0.271305 seconds

# 系统软件时钟
[root@string ~]# date
Mon Mar  5 10:03:30 CST 2029

# 获取硬件时间
[root@string ~]# hwclock -r
Fri 05 Mar 2021 10:13:19 AM CST  -0.473926 seconds

# 将硬件时间同步到系统时间
[root@string ~]# hwclock -r
Fri 05 Mar 2021 10:13:19 AM CST  -0.473926 seconds
[root@string ~]# date
Mon Mar  5 10:06:20 CST 2029
[root@string ~]# hwclock -s
[root@string ~]# date
Fri Mar  5 10:14:19 CST 2021

# 查看时区状态
[root@string ~]# timedatectl status
      Local time: Fri 2021-03-05 10:26:39 CST
  Universal time: Fri 2021-03-05 02:26:39 UTC
        RTC time: Fri 2021-03-05 02:26:33
       Time zone: Asia/Shanghai (CST, +0800)
     NTP enabled: n/a
NTP synchronized: no
 RTC in local TZ: no
      DST active: n/a

# 设置时区
[root@string ~]# timedatectl set-timezone Asia/Shanghai

重启和关机机器

[root@string ~]# reboot 
[root@string ~]# init 6
[root@string ~]# shutdown -r 0   #重启
[root@string ~]# halt 

# 重启
reboot

# 关机
shutdown -h 0
posted @ 2021-03-09 14:53  小绵  阅读(576)  评论(0编辑  收藏  举报