当前位置:   article > 正文

服务管理,网络管理_localhost.localdomain error [12231.b170836.253.119

localhost.localdomain error [12231.b170836.253.1193]

1.服务管理

在这里插入图片描述
##这个是服务管理的一些常用命令


[cxg@localhost ~]$ su -

Password: 
Last login: Sun Apr 26 10:56:25 CST 2020 on pts/1
  • 1
  • 2

[root@localhost ~]# systemctl li##这时候我们想不起来要输入的具体命令,输入一半可以连续按两下TAB进行提示,下面就是提示

link               list-dependencies  list-jobs          list-sockets       list-timers        list-unit-files    list-units   
  • 1

[root@localhost ~]# systemctl list-units##列出所有的可操作单元(下方的输出我们只截取部分的)

UNIT                                                                               LOAD   ACTIVE SUB       DESCRIPTION
proc-sys-fs-binfmt_misc.automount                                                  loaded active waiting   Arbitrary Executable File Formats File System Automount Point
sys-devices-pci0000:00-0000:00:10.0-host2-target2:0:0-2:0:0:0-block-sda-sda1.device loaded active plugged   VMware_Virtual_S 1
sys-devices-pci0000:00-0000:00:10.0-host2-target2:0:0-2:0:0:0-block-sda-sda2.device loaded active plugged   LVM PV ABhzBV-2KMV-JkHc-PAN8-TlYO-sqQV-UcFIm3 on /dev/sda2 2
sys-devices-pci0000:00-0000:00:10.0-host2-target2:0:0-2:0:0:0-block-sda.device     loaded active plugged   VMware_Virtual_S
  • 1
  • 2
  • 3
  • 4
  • 5

[root@localhost ~]# systemctl status##由于上方的可操作的较多,我们选择status底层点的操作单元,方便

● localhost.localdomain
    State: running
     Jobs: 0 queued
   Failed: 0 units
    Since: Sat 2020-04-25 17:30:17 CST; 17h ago
   CGroup: /
           ├─1 /usr/lib/systemd/systemd --switched-root --system --deserialize 22
           ├─user.slice
           │ └─user-1000.slice
           │   └─session-1.scope
           │     ├─ 8379 gdm-session-worker [pam/gdm-password]
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

[root@localhost ~]# systemctl status sshd##这个是查看服务状态,通过下面的代码我们可以看到active(running)程序正在运行,(这个命令也是远程的安全连接端口)

● sshd.service - OpenSSH server daemon
   Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled)
   Active: active (running) since Sat 2020-04-25 17:30:43 CST; 17h ago
     Docs: man:sshd(8)
           man:sshd_config(5)
 Main PID: 7514 (sshd)
    Tasks: 1
   CGroup: /system.slice/sshd.service
           └─7514 /usr/sbin/sshd -D
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

[root@localhost ~]# cd /usr/lib/systemd/system/##进入sshd端口
[root@localhost system]# ls

abrt-ccpp.service                        graphical.target.wants                 plymouth-poweroff.service                      sysinit.target
abrtd.service                            gssproxy.service                       plymouth-quit.service                          sysinit.target.wants
abrt-oops.service                        halt-local.service                     plymouth-quit-wait.service                     sys-kernel-config.mount
abrt-pstoreoops.service                  halt.target                            plymouth-read-write.service                    sys-kernel-debug.mount
abrt-vmcore.service                      halt.target.wants                      plymouth-reboot.service                        syslog.socket
abrt-xorg.service                        hibernate.target                       plymouth-start.service                         syslog.target.wants
accounts-daemon.service                  hybrid-sleep.target                    plymouth-switch-root.service                   sysstat.service
alsa-restore.service                     hypervfcopyd.service                   polkit.service                                 systemd-ask-password-console.path
alsa-state.service                       hypervkvpd.service                     postfix.service                                systemd-ask-password-console.service
anaconda-direct.service                  hypervvssd.service                     poweroff.target                                systemd-ask-password-plymouth.path
anaconda-nm-config.service               initial-setup-graphical.service        poweroff.target.wants                          systemd-ask-password-plymouth.service
anaconda-noshell.service                 initial-setup-reconfiguration.service  printer.target             
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

[root@localhost system]# ll *.service##可以看到sshd服务的端口

-rw-r--r--. 1 root root  275 Aug 20  2018 abrt-ccpp.service
-rw-r--r--. 1 root root  380 Aug 20  2018 abrtd.service
-rw-r--r--. 1 root root  361 Aug 20  2018 abrt-oops.service
-rw-r--r--. 1 root root  266 Aug 20  2018 abrt-pstoreoops.service
-rw-r--r--. 1 root root  262 Aug 20  2018 abrt-vmcore.service
-rw-r--r--. 1 root root  311 Aug 20  2018 abrt-xorg.service
-rw-r--r--. 1 root root  729 Jul 20  2018 accounts-daemon.service
-rw-r--r--. 1 root root  569 May 31  2018 alsa-restore.service
-rw-r--r--. 1 root root  465 May 31  2018 alsa-state.service
-rw-r--r--. 1 root root  682 Sep 26  2018 anaconda-direct.service
-rw-r--r--. 1 root root  185 Sep 26  2018 anaconda-nm-config.service
-rw-r--r--. 1 root root  660 Sep 26  2018 anaconda-noshell.service
-rw-r--r--. 1 root root  585 Sep 26  2018 anaconda-pre.service
-rw-r--r--. 1 root root  442 Sep 26  2018 anaconda.service
-rw-r--r--. 1 root root  532 Sep 26  2018 anaconda-shell@.service
-rw-r--r--. 1 root root  574 Sep 26  2018 anaconda-sshd.service
-rw-r--r--. 1 root root  498 Sep 26  2018 anaconda-tmux@.service
-rw-r--r--. 1 root root  275 May  3  2018 arp-ethers.service
-rw-r--r--. 1 root root  222 May 23  2018 atd.service
-rw-r--r--. 1 root root 1169 Jul 17  2018 auditd.service
-rw-r--r--. 1 root root  646 Sep 27  2018 auth-rpcgss-module.service
lrwxrwxrwx. 1 root root   14 Mar 31 18:11 autovt@.service -> getty@.service
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22

[root@localhost system]# systemctl stop sshd##我们现在停止sshd的服务端口
[root@localhost system]# systemctl status sshd##查看服务状态,发现他已经停止运行了 Active: inactive (dead)

● sshd.service - OpenSSH server daemon
   Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled)
   Active: inactive (dead) since Sun 2020-04-26 11:03:08 CST; 15s ago
     Docs: man:sshd(8)
           man:sshd_config(5)
  Process: 7514 ExecStart=/usr/sbin/sshd -D $OPTIONS (code=exited, status=0/SUCCESS)
 Main PID: 7514 (code=exited, status=0/SUCCESS)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

[root@localhost system]# systemctl start sshd##我们将stop改成start,让他再运行
[root@localhost system]# systemctl status sshd##可以看到他又开始运行了

● sshd.service - OpenSSH server daemon
   Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled)
   Active: active (running) since Sun 2020-04-26 11:03:34 CST; 2s ago
     Docs: man:sshd(8)
           man:sshd_config(5)
 Main PID: 22619 (sshd)
    Tasks: 1
   CGroup: /system.slice/sshd.service
           └─22619 /usr/sbin/sshd -D
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

[root@localhost system]# systemctl restart sshd##有时候我们也可以使用restart重启服务来再次启动

##总结:前面这几个命令总是用来控制当前的运行状态的。


[root@localhost system]# systemctl is-enabled sshd##查看sshd这个服务是开机自启的吗?

enabled
  • 1

##可以看到enabled ,他是开机自启的
[root@localhost system]# systemctl disable sshd##设定服务开机不启动(disable改为enable就是设置开机启动的)

Removed symlink /etc/systemd/system/multi-user.target.wants/sshd.service.
  • 1

##/etc/systemd/system/multi-user.target.wants/这个我们知道他是做软连接的,也是操作系统默认的运行级,muli-user可以看到这是多用户下的有网络,也就是我们用的这个终端。这段代码我们可以理解为系统在etc/systemd/system/multi-user.target.wants/这个目录后,这块系统就自动启动
[root@localhost system]# cd /etc/systemd/system/multi-user.target.wants/

[root@localhost multi-user.target.wants]# ll

total 0
lrwxrwxrwx. 1 root root 41 Mar 31 18:12 abrt-ccpp.service -> /usr/lib/systemd/system/abrt-ccpp.service
lrwxrwxrwx. 1 root root 37 Mar 31 18:12 abrtd.service -> /usr/lib/systemd/system/abrtd.service
lrwxrwxrwx. 1 root root 41 Mar 31 18:12 abrt-oops.service -> /usr/lib/systemd/system/abrt-oops.service
lrwxrwxrwx. 1 root root 43 Mar 31 18:12 abrt-vmcore.service -> /usr/lib/systemd/system/abrt-vmcore.service
lrwxrwxrwx. 1 root root 41 Mar 31 18:12 abrt-xorg.service -> /usr/lib/systemd/system/abrt-xorg.service
lrwxrwxrwx. 1 root root 35 Mar 31 18:14 atd.service -> /usr/lib/systemd/system/atd.service
lrwxrwxrwx. 1 root root 38 Mar 31 18:12 auditd.service -> /usr/lib/systemd/system/auditd.service
lrwxrwxrwx. 1 root root 44 Mar 31 18:14 avahi-daemon.service -> /usr/lib/systemd/system/avahi-daemon.service
lrwxrwxrwx. 1 root root 37 Mar 31 18:11 brandbot.path -> /usr/lib/systemd/system/brandbot.path
lrwxrwxrwx. 1 root root 37 Mar 31 18:11 crond.service -> /usr/lib/systemd/system/crond.service
lrwxrwxrwx. 1 root root 33 Mar 31 18:12 cups.path -> /usr/lib/systemd/system/cups.path
lrwxrwxrwx. 1 root root 36 Mar 31 18:12 cups.service -> /usr/lib/systemd/system/cups.service
lrwxrwxrwx. 1 root root 41 Mar 31 18:13 firewalld.service -> /usr/lib/systemd/system/firewalld.service
lrwxrwxrwx. 1 root root 61 Mar 31 18:13 initial-setup-reconfiguration.service -> /usr/lib/systemd/system/initial-setup-reconfiguration.service
lrwxrwxrwx. 1 root root 42 Mar 31 18:14 irqbalance.service -> /usr/lib/systemd/system/irqbalance.service
lrwxrwxrwx. 1 root root 35 Mar 31 18:12 ksm.service -> /usr/lib/systemd/system/ksm.service
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

##可以看到这些软连接都是自动开启的
[root@localhost multi-user.target.wants]# systemctl enable sshd##这个只设置开机时候的运行状态,不会对当前的运行状态产生变更

Created symlink from /etc/systemd/system/multi-user.target.wants/sshd.service to /usr/lib/systemd/system/sshd.service.
  • 1

##可以看到to后面的 /usr/lib/systemd/system/sshd.service.是软连接的真实位置,to前面是软连接。可以理解为只要/etc/systemd/system/multi-user.target.wants/这个目录上有/sshd.service,就会自动启动它


[root@localhost multi-user.target.wants]# systemctl enable sshd##开机自动启动

Created symlink from /etc/systemd/system/multi-user.target.wants/sshd.service to /usr/lib/systemd/system/sshd.service.
  • 1

[root@localhost multi-user.target.wants]# systemctl status sshd##可以看到这个enable命令不能对当前的运行状态产生影响,只能对开机时候的运行状态产生影响

● sshd.service - OpenSSH server daemon
   Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled)
   Active: active (running) since Sun 2020-04-26 11:03:49 CST; 48min ago
     Docs: man:sshd(8)
           man:sshd_config(5)
 Main PID: 22636 (sshd)
    Tasks: 1
   CGroup: /system.slice/sshd.service
           └─22636 /usr/sbin/sshd -D

Apr 26 11:03:49 localhost.localdomain systemd[1]: Stopped OpenSSH server daemon.
Apr 26 11:03:49 localhost.localdomain systemd[1]: Starting OpenSSH server daemon...
Apr 26 11:03:49 localhost.localdomain sshd[22636]: Server listening on 0.0.0.0 port 22.
Apr 26 11:03:49 localhost.localdomain systemd[1]: Started OpenSSH server daemon.
Apr 26 11:03:49 localhost.localdomain sshd[22636]: Server listening on :: port 22.
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

[root@localhost multi-user.target.wants]# systemctl disable sshd

Removed symlink /etc/systemd/system/multi-user.target.wants/sshd.service.
  • 1

[root@localhost multi-user.target.wants]# systemctl status sshd##可以看到开机不启动命令不能对当前状态产生影响

● sshd.service - OpenSSH server daemon
   Loaded: loaded (/usr/lib/systemd/system/sshd.service; disabled; vendor preset: enabled)
   Active: active (running) since Sun 2020-04-26 11:03:49 CST; 48min ago
     Docs: man:sshd(8)
           man:sshd_config(5)
 Main PID: 22636 (sshd)
   CGroup: /system.slice/sshd.service
           └─22636 /usr/sbin/sshd -D

Apr 26 11:03:49 localhost.localdomain systemd[1]: Stopped OpenSSH server daemon.
Apr 26 11:03:49 localhost.localdomain systemd[1]: Starting OpenSSH server daemon...
Apr 26 11:03:49 localhost.localdomain sshd[22636]: Server listening on 0.0.0.0 port 22.
Apr 26 11:03:49 localhost.localdomain systemd[1]: Started OpenSSH server daemon.
Apr 26 11:03:49 localhost.localdomain sshd[22636]: Server listening on :: port 22.
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

[root@localhost multi-user.target.wants]# systemctl disable --now sshd##但是加上–now那就相当于加上一个start命令,也就是相当于加systemctl disable命令和systemctl start与stop命令一起运行了,两步合一步
[root@localhost multi-user.target.wants]# systemctl status sshd

● sshd.service - OpenSSH server daemon
   Loaded: loaded (/usr/lib/systemd/system/sshd.service; disabled; vendor preset: enabled)
   Active: inactive (dead)
     Docs: man:sshd(8)
           man:sshd_config(5)

Apr 26 11:03:34 localhost.localdomain systemd[1]: Started OpenSSH server daemon.
Apr 26 11:03:49 localhost.localdomain systemd[1]: Stopping OpenSSH server daemon...
Apr 26 11:03:49 localhost.localdomain systemd[1]: Stopped OpenSSH server daemon.
Apr 26 11:03:49 localhost.localdomain systemd[1]: Starting OpenSSH server daemon...
Apr 26 11:03:49 localhost.localdomain sshd[22636]: Server listening on 0.0.0.0 port 22.
Apr 26 11:03:49 localhost.localdomain systemd[1]: Started OpenSSH server daemon.
Apr 26 11:03:49 localhost.localdomain sshd[22636]: Server listening on :: port 22.
Apr 26 11:53:02 localhost.localdomain systemd[1]: Stopping OpenSSH server daemon...
Apr 26 11:53:02 localhost.localdomain sshd[22636]: Received signal 15; terminating.
Apr 26 11:53:02 localhost.localdomain systemd[1]: Stopped OpenSSH server daemon.
[root@localhost multi-user.target.wants]# systemctl enable  --now sshd
Created symlink from /etc/systemd/system/multi-user.target.wants/sshd.service to /usr/lib/systemd/system/sshd.service.
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

[root@localhost multi-user.target.wants]# systemctl enable --now sshd##可以看到又开始运行了

`● sshd.service - OpenSSH server daemon
   Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled)
   Active: active (running) since Sun 2020-04-26 11:53:22 CST; 8s ago
     Docs: man:sshd(8)
           man:sshd_config(5)
 Main PID: 23598 (sshd)
    Tasks: 1
   CGroup: /system.slice/sshd.service
           └─23598 /usr/sbin/sshd -D

Apr 26 11:53:22 localhost.localdomain systemd[1]: Starting OpenSSH server daemon...
Apr 26 11:53:22 localhost.localdomain sshd[23598]: Server listening on 0.0.0.0 port 22.
Apr 26 11:53:22 localhost.localdomain sshd[23598]: Server listening on :: port 22.
Apr 26 11:53:22 localhost.localdomain systemd[1]: Started OpenSSH server daemon.
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

###对于systemctl enable和systemctl disable我们可以利用secureCRT来进行操作演示

在secureCRT里面:
[root@localhost ~]# systemctl status sshd##查看服务状态,因为我们用secureCRT也是属于远程安全链接控制,可以看到服务状态是允许的,可以接下来的操作

● sshd.service - OpenSSH server daemon
   Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled)
   Active: active (running) since Mon 2020-04-27 00:16:10 CST; 6h ago
     Docs: man:sshd(8)
           man:sshd_config(5)
 Main PID: 7653 (sshd)
    Tasks: 1
   CGroup: /system.slice/sshd.service
           └─7653 /usr/sbin/sshd -D

Apr 27 00:16:09 localhost.localdomain systemd[1]: Starting OpenSSH server dae...
Apr 27 00:16:10 localhost.localdomain sshd[7653]: Server listening on 0.0.0.0...
Apr 27 00:16:10 localhost.localdomain sshd[7653]: Server listening on :: port...
Apr 27 00:16:10 localhost.localdomain systemd[1]: Started OpenSSH server daemon.
Hint: Some lines were ellipsized, use -l to show in full.
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

[root@localhost ~]# systemctl isolate muli-user.target##将linux系统直接切换为多用户的模式(就是没有图像显示的那种和cmd一样的),指令输完后,系统已经变成没有鼠标的多用户模式了
[root@localhost ~]# systemctl isloate graphical.target##将linux系统直接切换为图形模式,系统又切换回图形模式了

Removed symlink /etc/systemd/system/default.target.
Created symlink from /etc/systemd/system/default.target to /usr/lib/systemd/system/multi-user.target.
  • 1
  • 2

##可以看到remove去除掉symlink /etc/systemd/system/default.target.这个链接,to给他连接到multi-user.target图形模式上
[root@localhost ~]# systemctl set-default multi-user.target##将系统切换为多用户模式,但是需要重启后才生效(这个指令是设置操作系统默认的运行级
[root@localhost ~]# reboot##重启系统,重启完成后,我们发现系统已经变成多用户的模式了
[root@localhost ~]# systemctl set-default graphical.target##将系统切换图形模式,但是需要重启后才生效(这个指令是设置操作系统默认的运行级
[root@localhost ~]# reboot##重启系统
[root@localhost ~]# systemctl mask sshd##这个mask命令是锁定sshd这个远程链接服务

Created symlink from /etc/systemd/system/sshd.service to /dev/null.
  • 1

##可以看到to /dev/null.,吧这个sshd这个连接到黑洞回收站去了,就是没有连接了,自然也就不存在可以连接了,也就锁定了
[root@localhost ~]# systemctl start sshd##我们现在启动sshd发现失败了,因为被mask锁定了

Failed to start sshd.service: Unit is masked.
  • 1

[root@localhost ~]# systemctl unmask sshd##我们利用unmask取消锁定后

Removed symlink /etc/systemd/system/sshd.service.
  • 1

[root@localhost ~]# systemctl start sshd##发现又可以连接运行了

2.网络管理

在这里插入图片描述
在这里插入图片描述

##这个是网络管理的一些常用命令

##ip, 网关和dns是上网必须有的,但是如果是局域网的话,可以只有IP也行。
  • 1

[root@localhost ~]# cd /etc/sys

sysconfig/ sysctl.d/  systemd/   
  • 1

[root@localhost ~]# cd /etc/sysconfig/

cbq/             console/         modules/         network-scripts/ rhn/             
  • 1

[root@localhost ~]# cd /etc/sysconfig/network-scripts##进入网络配置
[root@localhost network-scripts]# ls

ifcfg-ens33  ifdown-eth   ifdown-isdn    ifdown-sit       ifup          ifup-ib    ifup-plip   ifup-routes    ifup-tunnel        network-functions-ipv6
ifcfg-lo     ifdown-ib    ifdown-post    ifdown-Team      ifup-aliases  ifup-ippp  ifup-plusb  ifup-sit       ifup-wireless
ifdown       ifdown-ippp  ifdown-ppp     ifdown-TeamPort  ifup-bnep     ifup-ipv6  ifup-post   ifup-Team      init.ipv6-global
ifdown-bnep  ifdown-ipv6  ifdown-routes  ifdown-tunnel    ifup-eth      ifup-isdn  ifup-ppp    ifup-TeamPort  network-functions
  • 1
  • 2
  • 3
  • 4

[root@localhost network-scripts]# pwd

/etc/sysconfig/network-scripts
  • 1

[root@localhost network-scripts]# vim ifcfg-ens33##对网关进行修改

BOOTPROTO=static
DEVICE=ens33
ONBOOT=yes
IPADDR=192.168.0.100
PREFIX=24
GATEWAY=192.168.0.1
DNS1=114.114.114.114
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

##删除掉ens33的第一行


##我们接下来对网卡名称进行修改,原本是ens33这种,我们将他换成以前的那种eth0,eth1,连续排列那种网卡名

[root@localhost network-scripts]# vim /boot/grub2/grub.cfg##这个是内核的参数,我们云计算的时候要求所有的硬件和设备标识一致,不一致的话,服务器的配置文件不好设置

menuentry 'Red Hat Enterprise Linux Server (3.10.0-957.el7.x86_64) 7.6 (Maipo)' --class red --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-957.el7.x86_64-advanced-ed80b36e-3eb4-44e5-a17d-9e6a13b37967' {
        load_video
        set gfxpayload=keep
        insmod gzio
        insmod part_msdos
        insmod xfs
        set root='hd0,msdos1'
        if [ x$feature_platform_search_hint = xy ]; then
          search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 --hint='hd0,msdos1'  04b6288f-68c6-408b-b1ef-b07078e9f7a5
        else
          search --no-floppy --fs-uuid --set=root 04b6288f-68c6-408b-b1ef-b07078e9f7a5
        fi
        linux16 /vmlinuz-3.10.0-957.el7.x86_64 root=/dev/mapper/rhel-root ro rd.lvm.lv=rhel/root rd.lvm.lv=rhel/swap rhgb quiet LANG=en_US.UTF-8 net.ifnames=0
        initrd16 /initramfs-3.10.0-957.el7.x86_64.img
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

##这两条分别是内核的启动参数,上面是第一条启动参数,下面是第二条启动参数,第二条一般不用,##我们在第一条的倒数第二行的.UTF-8 后面加上 net.ifnames=0表示禁用给网卡命名的模式

menuentry 'Red Hat Enterprise Linux Server (0-rescue-4dd8bf0a62964b709726bb3d5cdda54e) 7.6 (Maipo)' --class red --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-0-rescue-4dd8bf0a62964b709726bb3d5cdda54e-advanced-ed80b36e-3eb4-44e5-a17d-9e6a13b37967' {
        load_video
        insmod gzio
        insmod part_msdos
        insmod xfs
        set root='hd0,msdos1'
        if [ x$feature_platform_search_hint = xy ]; then
          search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 --hint='hd0,msdos1'  04b6288f-68c6-408b-b1ef-b07078e9f7a5
        else
          search --no-floppy --fs-uuid --set=root 04b6288f-68c6-408b-b1ef-b07078e9f7a5
        fi
        linux16 /vmlinuz-0-rescue-4dd8bf0a62964b709726bb3d5cdda54e root=/dev/mapper/rhel-root ro rd.lvm.lv=rhel/root rd.lvm.lv=rhel/swap rhgb quiet
        initrd16 /initramfs-0-rescue-4dd8bf0a62964b709726bb3d5cdda54e.img
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

[root@localhost network-scripts]# reboot##重启后才能生效
[root@localhost ~]# ip addr##重启后我们发现我们的网关已经由ens33变为eth0了,已经完成命名,但是和secureCRT的链接断了

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: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:82:f7:e7 brd ff:ff:ff:ff:ff:ff
3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
    link/ether 52:54:00:bd:87:59 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 pfifo_fast master virbr0 state DOWN group default qlen 1000
    link/ether 52:54:00:bd:87:59 brd ff:ff:ff:ff:ff:ff
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

##这是由于我们更换了网关命,但是和secureCRT的桥接信息还是原本ens33的信息,所以我们也要对联结的端口信息进行修改
[root@localhost ~]# cd /etc/sysconfig/network-scripts/ ##进入网关设置
[root@localhost network-scripts]# vim ifcfg-ens33##在这里面将DEVICE=ens33改为DEVICE=eth0
[root@localhost network-scripts]# mv ifcfg-ens33 ifcfg-eth0##将ens33的信息移动到eth0里面
[root@localhost network-scripts]# systemctl restart NetworkManager##重启网络后发现,我们的连接已经做好恢复了


##再切换回linux
[root@localhost network-scripts]# ip addr

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: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:82:f7:e7 brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.100/24 brd 192.168.0.255 scope global noprefixroute eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe82:f7e7/64 scope link 
       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:bd:87:59 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 pfifo_fast master virbr0 state DOWN group default qlen 1000
    link/ether 52:54:00:bd:87:59 brd ff:ff:ff:ff:ff:ff
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

[root@localhost network-scripts]# cd /etc/syconfig/network-scripts/
[root@localhost network-scripts]# ls##创建的网络接口的信息也已经改变

ifcfg-eth0  ifdown-bnep  ifdown-ippp  ifdown-post    ifdown-sit       ifdown-tunnel  ifup-bnep  ifup-ippp  ifup-plip   ifup-ppp     ifup-Team      ifup-wireless      network-functions-ipv6
ifcfg-lo    ifdown-eth   ifdown-ipv6  ifdown-ppp     ifdown-Team      ifup           ifup-eth   ifup-ipv6  ifup-plusb  ifup-routes  ifup-TeamPort  init.ipv6-global
ifdown      ifdown-ib    ifdown-isdn  ifdown-routes  ifdown-TeamPort  ifup-aliases   ifup-ib    ifup-isdn  ifup-post   ifup-sit     ifup-tunnel    network-functions
  • 1
  • 2
  • 3

[root@localhost network-scripts]# cat ifcfg-eth0

BOOTPROTO=static
DEVICE=eth0
ONBOOT=yes
IPADDR=192.168.0.100
PREFIX=24
GATEWAY=192.168.0.1
DNS1=114.114.114.114
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

##可以看到所有的网卡信息都已经修改完成,此时我们再插入一个网卡的时候,新的网卡命名为eth1,eth2,eth3 等等,按照规律排列。
##拓展:我们一般在生产环节,一般有多个网卡,云主机一个网,管理一个网,外部独立连接一个网,这是因为如果都设置成一个网的话,如果数据出现堵塞,会让管网出现未响应的情况
##1.上面的BOOTPROTO=static 是告诉我们通过指定方式的办法来获得地址 这里我们选择静态static,动态的话将static改为dhcp
2.DEVICE=eth0,这个是设备名,这个名必须和ip addr里面的网关设备名一致
3.ONBOOT=yes这个是开机自动启动的意思,就是说网卡在开机的时候自动激活
4.IPADDR=192.168.0.100,ip地址
5.PREFIX=24子网掩码=24,也可以使用NETMSAK=255.255.255.0来进行替换,但是前者更加简单方便

##比如说我们想设置多个IP地址就可以:
[root@localhost network-scripts]# vim ifcfg-eth0

BOOTPROTO=static
DEVICE=eth0
ONBOOT=yes
IPADDR1=192.168.0.100
IPADDR2=172.25.0.100
PREFIX1=24
PREFIX2=24
GATEWAY1=192.168.0.1
DNS1=114.114.114.114
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

##分别用IPADDR1和IPADDR2和子网掩码1和2,网关1和2区分每个IP地址,这是针对不同的输出,不同的网卡配置不同的IP,走不一样的网关

[root@localhost network-scripts]# ip addr ##查看ip地址发现第二个172.25.0.100的IP地址没有生效

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:82:f7:e7 brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.100/24 brd 192.168.0.255 scope global noprefixroute eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe82:f7e7/64 scope link 
       valid_lft forever preferred_lft forever
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

[root@localhost network-scripts]# systemctl restart NetworkManager##我们重启下网络
[root@localhost network-scripts]# ip addr##发现还是没有生效

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:82:f7:e7 brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.100/24 brd 192.168.0.255 scope global noprefixroute eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe82:f7e7/64 scope link 
       valid_lft forever preferred_lft forever
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

[root@localhost network-scripts]# systemctl stop NetworkManager##这时候我们采用先关闭网络服务
[root@localhost network-scripts]# systemctl disable NetworkManager##再关闭开机自启动

Removed symlink /etc/systemd/system/multi-user.target.wants/NetworkManager.service.
Removed symlink /etc/systemd/system/dbus-org.freedesktop.NetworkManager.service.
Removed symlink /etc/systemd/system/dbus-org.freedesktop.nm-dispatcher.service.
Removed symlink /etc/systemd/system/network-online.target.wants/NetworkManager-wait-online.service.
  • 1
  • 2
  • 3
  • 4

[root@localhost network-scripts]# systemctl restart network##再重新启动网络后,注意这个network和上面的MangerNetwork不一样,这个中专属于rhel7以前的系统,erhel8就不能使用了,针对rhel8的系统我们采用的指令为nmcli connection show
[root@localhost network-scripts]# ip addr##这时候172.25.0.100的IP地址已经激活

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:82:f7:e7 brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.100/24 brd 192.168.0.255 scope global noprefixroute eth0
       valid_lft forever preferred_lft forever
    inet 172.25.0.100/24 brd 172.25.0.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe82:f7e7/64 scope link 
       valid_lft forever preferred_lft forever
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

[root@localhost network-scripts]# vim ifcfg-eth0

BOOTPROTO=static
DEVICE=eth0
ONBOOT=yes
IPADDR=192.168.0.100
PREFIX=24
GATEWAY=192.168.0.1
DNS1=114.114.114.114
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

[root@localhost network-scripts]# systemctl restart network
[root@localhost network-scripts]# ip addr

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:82:f7:e7 brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.100/24 brd 192.168.0.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe82:f7e7/64 scope link 
       valid_lft forever preferred_lft forever
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

[root@localhost network-scripts]# route -n ##查看网关

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.0.1     0.0.0.0         UG    0      0        0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U     1002   0        0 eth0
192.168.0.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0
192.168.122.0   0.0.0.0         255.255.255.0   U     0      0        0 virbr0
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

[root@localhost network-scripts]# cat /etc/resolv.conf ##查看DNS

nameserver 114.114.114.114
search localdomain
  • 1
  • 2

[root@localhost network-scripts]# ll ifcfg-eth0##这个其实只是把IP地址,DNS 等等这些写到一个文件里,系统会根据文件信息,自动生成新的文件地址到各处比如上面查看dns和ip地址的位置文件,我们没有修改过他的文件,但是他的文件就随着我们ifcfg-eth0内容的修改进行改变
[root@localhost network-scripts]# vim /etc/resolv.conf ##下面这个是他原本的内容,我们删除第一行

nameserver 114.114.114.114
search localdomain
  • 1
  • 2

##删除第一行

search localdomain
  • 1

[root@localhost network-scripts]# systemctl restart network##重新启动网络,看修改后的ip地址,网关,还有dns
[root@localhost network-scripts]# ip addr##发现没有发生改变
[root@localhost network-scripts]#route -n##没有发生改变
[root@localhost network-scripts]# cat /etc/resolv.conf ##发现没有改变

nameserver 114.114.114.114
search localdomain
  • 1
  • 2

[root@localhost ~]# ip addr

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: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:82:f7:e7 brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.100/24 brd 192.168.0.255 scope global noprefixroute eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe82:f7e7/64 scope link 
       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:bd:87:59 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 pfifo_fast master virbr0 state DOWN group default qlen 1000
    link/ether 52:54:00:bd:87:59 brd ff:ff:ff:ff:ff:ff
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

[root@localhost ~]# route -n##查看网关

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.0.1     0.0.0.0         UG    100    0        0 eth0
192.168.0.0     0.0.0.0         255.255.255.0   U     100    0        0 eth0
192.168.122.0   0.0.0.0         255.255.255.0   U     0      0        0 virbr0
  • 1
  • 2
  • 3
  • 4
  • 5

[root@localhost ~]# route del default gw 192.168.0.1##删除掉192.168.0.1这个网关

[root@localhost ~]# route -n##发现已经没有这个网关了

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.0.0     0.0.0.0         255.255.255.0   U     100    0        0 eth0
192.168.122.0   0.0.0.0         255.255.255.0   U     0      0        0 virbr0
  • 1
  • 2
  • 3
  • 4

[root@localhost ~]# ip addr##查看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: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:82:f7:e7 brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.100/24 brd 192.168.0.255 scope global noprefixroute eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe82:f7e7/64 scope link 
       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:bd:87:59 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 pfifo_fast master virbr0 state DOWN group default qlen 1000
    link/ether 52:54:00:bd:87:59 brd ff:ff:ff:ff:ff:ff
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

[root@localhost ~]# ip addr del 192.168.0.100/24 dev eth0##我们将IP地址也删掉

[root@localhost ~]# ip addr##可以看到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: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:82:f7:e7 brd ff:ff:ff:ff:ff:ff
    inet6 fe80::20c:29ff:fe82:f7e7/64 scope link 
       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:bd:87:59 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 pfifo_fast master virbr0 state DOWN group default qlen 1000
    link/ether 52:54:00:bd:87:59 brd ff:ff:ff:ff:ff:ff

BOOTPROTO=static
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

[root@localhost ~]# systemctl stop network##再将网络停掉

[root@localhost ~]# ip addr##可以看到此时IP地址,网关,dns都是没有的

1: lo: <LOOPBACK> mtu 65536 qdisc noqueue state DOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:82:f7:e7 brd ff:ff:ff:ff:ff:ff
3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
    link/ether 52:54:00:bd:87:59 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 pfifo_fast master virbr0 state DOWN group default qlen 1000
    link/ether 52:54:00:bd:87:59 brd ff:ff:ff:ff:ff:ff

DEVICE=eth0
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

[root@localhost sysconfig]# cd /etc/sysconfig/network-scripts
[root@localhost network-scripts]# vim ifcfg-eth0##我们再给IPADDR PROFIX GATEWAY DNS1这些都注释上

ONBOOT=yes
#IPADDR=192.168.0.100
#PREFIX=24
#GATEWAY=192.168.0.1
#DNS1=114.114.114.114
  • 1
  • 2
  • 3
  • 4
  • 5

[root@localhost network-scripts]# systemctl start network##重新启动网络
[root@localhost network-scripts]# ip addr##他会激活我们的设备,但是没有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: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:82:f7:e7 brd ff:ff:ff:ff:ff:ff
    inet6 fe80::20c:29ff:fe82:f7e7/64 scope link 
       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:bd:87:59 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 pfifo_fast master virbr0 state DOWN group default qlen 1000
    link/ether 52:54:00:bd:87:59 brd ff:ff:ff:ff:ff:ff
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

[root@localhost network-scripts]# route -n##没有网关

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.122.0   0.0.0.0         255.255.255.0   U     0      0        0 virbr0
  • 1
  • 2
  • 3

[root@localhost network-scripts]# cat /etc/resolv.conf##没有dns

##这时候我们的设备激活了,可以往里面加ip 网关,dns的信息

[root@localhost network-scripts]# ip addr add 192.168.0.200/24 dev eth0##加入IP地址的信息给eth0
[root@localhost network-scripts]# ip addr##可以发现我们的IP已经可以通了,可以在cmd里面ping192.168.0.200看是否通

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: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:82:f7:e7 brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.200/24 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe82:f7e7/64 scope link 
       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:bd:87:59 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 pfifo_fast master virbr0 state DOWN group default qlen 1000
    link/ether 52:54:00:bd:87:59 brd ff:ff:ff:ff:ff:ff
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

[root@localhost network-scripts]# ping baidu.com##我们ping个网站发现ping不通,这是因为先要上网只有IP地址是不行的,还需要网关和dns

ping: baidu.com: Name or service not known
  • 1

[root@localhost network-scripts]# route add default gw 192.168.0.1##加入网关
[root@localhost network-scripts]# vim /etc/resolv.conf##输入dns ‘nameserver 114.114.114.114‘,这个nameserver最多可以设置三个

nameserver 114.114.114.114
  • 1

[root@localhost network-scripts]# ping baidu.com##ping个网站发现可以上网了

PING baidu.com (39.156.69.79) 56(84) bytes of data.
64 bytes from 39.156.69.79 (39.156.69.79): icmp_seq=1 ttl=52 time=70.9 ms
64 bytes from 39.156.69.79 (39.156.69.79): icmp_seq=2 ttl=52 time=31.0 ms
--- baidu.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 31.089/51.019/70.950/19.931 ms
^C
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

##上网的三要素:IP地址,网关,dns。但是上面的命令只适合当前的环境,系统网络后就又返回到原来的情况,请看下面

[root@localhost network-scripts]# systemctl restart network##重启网络
[root@localhost network-scripts]# ip addr##发现ip地址,网关,dns又都没有了

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: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:82:f7:e7 brd ff:ff:ff:ff:ff:ff
    inet6 fe80::20c:29ff:fe82:f7e7/64 scope link 
       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:bd:87:59 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 pfifo_fast master virbr0 state DOWN group default qlen 1000
    link/ether 52:54:00:bd:87:59 brd ff:ff:ff:ff:ff:ff
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

[root@localhost network-scripts]# route -n##没有网关

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.122.0   0.0.0.0         255.255.255.0   U     0      0        0 virbr0
  • 1
  • 2
  • 3

[root@localhost network-scripts]# cat /etc/resolv.conf

nameserver 114.114.114.114
  • 1

##这是为什么呢,因为我们没有把我们的网络设置信息保存在ifcfg-eth0里面(记得上面的时候,我们把ifcfg-eth0里面的ip,网关,dns都注释让他失效了吗?)
[root@localhost network-scripts]# vim ifcfg-eth0

OTPROTO=static
DEVICE=eth0
ONBOOT=yes
#IPADDR=192.168.0.100
#PREFIX=24
#GATEWAY=192.168.0.1
#DNS1=114.114.114.114
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

`
##将注释的都取消

OTPROTO=static
DEVICE=eth0
ONBOOT=yes
IPADDR=192.168.0.100
PREFIX=24
GATEWAY=192.168.0.1
DNS1=114.114.114.114
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

[root@localhost network-scripts]# systemctl restart network
[root@localhost network-scripts]# ip addr

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: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:82:f7:e7 brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.100/24 brd 192.168.0.255 scope global noprefixroute eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe82:f7e7/64 scope link 
       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:bd:87:59 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 pfifo_fast master virbr0 state DOWN group default qlen 1000
    link/ether 52:54:00:bd:87:59 brd ff:ff:ff:ff:ff:ff
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

##这个时候我们重新启动后,发现设置依然在生效,所以想要永久的生效,就需要把网络信息写在/etc/sysconfig/network-scripts下面的iifcfg-eth0里面。这也同时和我们前面所说的相对应,linux系统是其实只是把IP地址,DNS 等等这些写到一个文件里,系统会根据文件信息,自动生成新的文件地址到各处比如上面查看dns和ip地址的位置文件,我们没有修改过他的文件,但是他的文件就随着我们ifcfg-eth0内容的修改进行改变,这个ifcfg-eth0算是网络设置的源文件,虽然 ip addr add这些指令也可以加入ip地址和网关,但是他们相当于交互的中间文件,只能支撑我们当前状态的网络信息修改,要想让网络信息从根源上一直是修改后的状态,必须在ifcfg-eth0这个网络源文件进行修改才行


##虚拟网络的设置我们设置的是桥接的模式,现在我们切换下,使用NATt模式设置下网络模式

在这里插入图片描述
##选择NAT模式,他会自动设置一个子网IP 192.168.190.0 如果不喜欢,我们也可以点击“DHCP设置”修改这个ip
##点击“确定”
在这里插入图片描述
##这两个设置好之后点击“确定”

[root@localhost network-scripts]# vim ifcfg-eth0

BOOTPROTO=dhcp
DEVICE=eth0
ONBOOT=yes
#IPADDR=192.168.0.100
#PREFIX=24
#GATEWAY=192.168.0.1
#DNS1=114.114.114.114
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

##NAT模式只需要前三项并且将原本的BOOTPROTO=static改为动态的dhcp,再将后面原本静态的设置都注释掉,让他失效
[root@localhost network-scripts]# systemctl restart network##重新启动网络,看我们的的设置
[root@localhost network-scripts]# ip addr##可以看到ip地址已经变为第一张图片的子网IP192.168.190.129了

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: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:82:f7:e7 brd ff:ff:ff:ff:ff:ff
    inet 192.168.190.129/24 brd 192.168.190.255 scope global noprefixroute dynamic eth0
       valid_lft 1791sec preferred_lft 1791sec
3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
    link/ether 52:54:00:bd:87:59 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 pfifo_fast master virbr0 state DOWN group default qlen 1000
    link/ether 52:54:00:bd:87:59 brd ff:ff:ff:ff:ff:ff
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

[root@localhost network-scripts]# route -n##网关也有

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.190.1   0.0.0.0         UG    100    0        0 eth0
192.168.122.0   0.0.0.0         255.255.255.0   U     0      0        0 virbr0
192.168.190.0   0.0.0.0         255.255.255.0   U     100    0        0 eth0
  • 1
  • 2
  • 3
  • 4
  • 5

[root@localhost network-scripts]# cat /etc/resolv.conf##dns也有

search localdomain
nameserver 192.168.190.1
  • 1
  • 2

[root@localhost network-scripts]# ping baidu.com##也可以上网

PING baidu.com (39.156.69.79) 56(84) bytes of data.
64 bytes from 39.156.69.79 (39.156.69.79): icmp_seq=1 ttl=128 time=31.1 ms
64 bytes from 39.156.69.79 (39.156.69.79): icmp_seq=2 ttl=128 time=30.4 ms
^C
--- baidu.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 30.469/30.825/31.182/0.397 ms
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

##我们又想设置回桥接模式的话:
在这里插入图片描述

在这里插入图片描述

##上面两步设置好之后,在Linux系统输入vim ifcfg-eth0,将dhcp改为static,后面#注释的全部去掉后保存,然后再systemctl restart network,再查看ip addr发现已经变为我们静态的IP地址了,route -n,cat /etc/resov.conf ,ping baidu.com,发现都没有问题的话,就修改完成。


声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/436084
推荐阅读
相关标签
  

闽ICP备14008679号