网络的管理

来源:互联网 发布:windows vue webpack 编辑:程序博客网 时间:2024/06/05 10:20
一.真机里面连接网络
1.先用命令  vim  /etc/sysconfig/network-scripts/ifcfg-网卡配置文件
   删除里面的网关  GATEWAY=ip 那一项
2.用命令 systemctl restart network 重启
3.在wi-fi里面直接连接一下即可





二.伪装真机为路由器,管理虚拟机网络
(1)在真机中所要做的操作

1.systemctl start      firewalld
   systemctl enable  firewalld     开启防火墙

2.firewall-cmd --permanent  --add-masquerade
   firewall-cmd --permanent  --add-rich-rule'rule family=ipv4 source address=网络ip masquerade'
   firewall-cmd --reload               对真机进行伪装
注意:firewall-cmd --list-all    可以检查是否已经伪装好

用ifconfig 查看已连接的网络ip     伪装时所要用到的ip
用 cat /etc/resolv.conf 查看dns服务器的ip 

(2)在虚拟机中所要做的操作

1.在 /etc/sysconfig/network 中设置网关  使和真机在一个网段
   GATEWAY=ip
注意: 设置完后   systemctl restart network 进行重启

2.在  /etc/resolv.conf            中设置dns服务器的ip和真机里面的一样

3.用 route -n命令查看网关是否设置好

注意:出现问题,查看/etc/sysconfig/network-scripts/下的网卡配置,若网卡坏掉,在真机里面 virt-manager下选择虚拟机删除网卡重新添加一个。
           排错时,先 systemctl stop NetworkManager.service关闭网络状态的记录,重启网络服务。


三.ip的获取
1.图形界面
   nm-connection-editor
2.文本化界面
   nmtui
3.dhcp动态获取
   vim /etc/sysconfig/network-scripts/ifcfg-eth0
    DEVICE=eth0                                                  接口使用的设备
    BOOTPROTO=dhcp                                       网卡工作的模式
    ONBOOT=yes                                                 网络服务开启时自动激活
    NAME=wzw                                                     网路接口的名称
    :wq
一定要记得:           systemctl restart network
4.静态网络
   vim /etc/sysconfig/network-scripts/ifcfg-eth0
   DEVICE=eth0
   BOOTPROTO=none
   ONBOOT=yes
   NAME=wzw
   IPADDR=172.25.90.10                                      所设置的ip
   NETMASK=255.255.255.0 / PREFIX=24          子网掩码
   DNSI=IP                                                             设置的dns的ip
   GATEWAY=IP                                                    设置网关
                                 systemctl restart network
5.nmcli命令
   nmcli  connection add type ethernet con-name westos ifname eth0 autoconnect yes        添加dhcp网络
   nmcli  connection add type ethernet con-name westos ifname eth0 ip4 ip/24                     添加静态网络
   nmcli  connection delete westos                                                                                          删除westos链接
   nmcli  connection show                                                                                                        显示所有的网络链接
   nmcli  connection down  westos                                                                                          关闭指定的链接
   nmcli  connection up       westos                                                                                          开启指定的链接
   nmcli  connection modify" westos" ipv4.addresses new ip/24                                              修改ip
   nmcli  connection modify" westos" ipv4.method auto/manual                                               修改工作方式
   nmcli  device connect  eth0                                                                                                  开启设备
   nmcli  device disconnect  eth0                                                                                              关闭设备
   nmcli  device show                                                                                                                显示设备信息
   nmcli  device status                                                                                                               显示设备状态
 

6.本地解析文件
    vim /etc/hosts

7.本地解析文件和dns读取的优先级调整
   vim  /etc/nsswitch.conf
39 hosts:     files   dns                               哪个在前哪个优先