目录
一、网络配置基础
1.1、网络接口
先来对比一下RHEL6、RHEL7关于网络接口上的一些差别。
RHEL6 | RHEL7 | |
---|---|---|
配置文件位置 | /etc/sysconfig/networking-scripts/ifcfg-xxxx xxx是网卡名称。 | 这个已经不重要了。其实和6版本一样。 |
网卡命名规则 | 传统上,Linux网卡枚举命名为eth0、eth1、eth2……ethN。问题是这不能和物理网卡对应,随着设备的增加删除,这会导致名称和网卡的对应发生变化。非常不好。 | 根据固件、设备拓扑和设备类型分配固定的名称。
|
网卡重启 | 重启网络服务,不用service network restart全部网卡重启,而是用ifdown ifup单独重启某个网卡。 ifdown eth0 ifup eth0 | 使用NetworkManager服务的nmcli命令。注意,network和NetworkManager只是两个不同的网络管理程序,任选其一即可,推荐使用NetworkManager服务的nmcli命令。 nmcli connection up “System eth0” nmcli connection down “System eth0” |
网卡配置 | 修改/etc/sysconfig/networking-scripts/ifcfg-xxxx配置文件的内容。 IPADDR=172.25.0.11 NETMASK=255.255.255.0 GATEWAY=172.25.0.254 BOOTPROTO=static ONBOOT=yes | 使用nmcli命令行配置即可。 nmcli connection modify “System eth0” ipv4.addresses “172.25.0.11/24 172.25.0.254” ipv4.dns 172.25.254.254 ipv4.method manual connection.autoconnect yes |
一个网卡配置 多个IP地址 | 一个接口多个配置文件,命名方式如下 ifcfg-eth0 ifcfg-eht0:1 | 使用nmcli命令,用+ipv4.address nmcli connection modify “System eth0” +ipv4.addresses 1.1.1.1/8 |
主机名 | 修改配置文件/etc/sysconfig/network | /etc/hostname默认不存在 hostnamectl set-home xxx.xxx.xxx |
本地解析 | /etc/hosts | /etc/hosts |
安装centos7时,在Install页面,按tab键,然后在最后输入以下内容,可以修改网卡命名规则,从centos7的 ens32、ens33 改回到 centos6的 eth0、eth1、……命名规则。
net.ifnames=0 biosdevname=0
1.2、设置主机名
用hostnamectl命令查看、设置主机名。hostnamectl status 看到Static hostname是空的,Transient hostname是server0.example.com说明主机名是临时的,用hostname set-hostname来设置持久的主机名。
二、nmcli配置网络
2.1、配置固定的IP地址等
用nmcli命令配置网络。nmcli命令可以不用记选项参数,只需要用tab键就可以提示。用nmcli配置IP地址172.25.0.11/24,网关172.25.0.254,DNS 172.25.0.254。手动配置所以方法是manual,别忘记自动启动,否则重启后不能自动启动。最后手动up一下。注意网关的写法是直接加载IP地址后面的,在RHEL7.2以后有了ipv4.gateway就可以分开指定gateway了。
[root@server0 ~]# nmcli connection modify "System eth0" ipv4.addresses "172.25.0.11/24 172.25.0.254" ipv4.dns "172.25.0.254" ipv4.method manual connection.autoconnect yes
[root@server0 ~]#
[root@server0 ~]# nmcli connection up "System eth0"
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/1)
2.2、连接wifi
虽然服务器上一般不装无线网卡,但是我们还是把这个操作写下来,记录一下nmcli的强大。
[root@nano:~]# nmcli device wifi list
[root@nano:~]# nmcli device wifi connect "CMCC-W2aJ" password "********"
三、链路聚合等
未完待续