网络配置文件

centos/rocky系列网络配置文件

  • 主机名:

Centos 6之前版本

vim   /etc/sysconfig/network

              HOSTNAME=xxx.org

              执行hostname  xxx.org

Centos 7之后版本

               /etc/hostname

               执行:hostnamectl set-hostname  xxx.org

  • 配置IP地址

/etc/sysconfig/network-scripts/ifcfg-网卡名

DEVICE

NAME

#BOOTPROTO=dhcp(动态)

BOOTPROTO=static | none(静态)手动配置

IPADDR=

PREFIX=24  |  NETMASK=255.255.255.0

GATEWAY=

DNS1=

DNS2=

  • 添加多个网卡地址:

/etc/sysconfig/network-scripts/ifcfg-IFACE:label

增加文件:配置IP地址,可以以标签的形式添加

 

在一个文件中:另外在添加IPADDR#=

                                             PREFIX#=

生效执行命令

  • Centos 8:

执行:nmcli connection reload

           nmcli connection up 网卡名

  • Centos 7

执行:systemctl  restart network

  • Cento 6

执行:service network restart

  • 通用:

重启reboot

 

Ubuntu的网卡管理

配置文件:/etc/netplan/xxx.yaml。以xxx.yaml文件命名方式存放

  • 自动获取IP

vim  /etc/netplan/eth0.yaml

network:

version:2

renderer:network

ethernets:

   eth0:

      dhcp4:true

  • 配置静态IP

vim   /etc/netplan/eth0.yaml

network:

version:2

renderer:networkd

ethernets:

   eth0:

       addresses:[192.168.8.10/24,10.0.0.10/8]或者用下面两行

   - 192.168.8.10/24

   - 10.0.0.10/8

        gateway4: 10.0.0.2

    nameservers:

        search: [magedu.com,magedu.org]

        addresses: [180.76.76.76,8.8.8.8,1.1.1.1]

  • 执行命令使配置文件生效

netplan  apply

 

posted on 2023-01-12 18:15  smile^^  阅读(113)  评论(0)    收藏  举报