编辑网络配置文件

编辑 /etc/sysconfig/network-scripts/ifcfg-<name> 文件可以用来配置网络设备和连接,该文件中常见的一些配置如下表:

Static Dynamic Either
BOOTPROTO=none
IPADDR0=172.25.X.10
PREFIX0=24
GATEWAY0=172.25.X.254
DEFROUTE=yes
DNS1=172.25.254.254
BOOTPROTO=dhcp
DEVICE=eth0
NAME="System eth0"
ONBOOT=yes
UUID=f3e8dd32-3...
USERCTL=yes

一般配置文件修改完成后需要重新加载网络连接,具体通过:

# nmcli con reload
# nmcli con down "System eth0"
# nmcli con up "System eth0"

案例:配置 OpenShift master 和 node 节点为静态 IP 地址

配置 OpenShift master 和 两个 node 节点为静态 IP 地址,分别为 X.X.192.101, X.X.192.102, X.X.192.103,且外部能够 ping 通 master 和 node,master 和 node 之间也能互相 ping 通。

配置 master

备份原始配置文件
# cd /etc/sysconfig/network-scripts/
# cp ifcfg-eth0 ifcfg-eth0-bak
编辑ifcfg-eth0,内容如下
BOOTPROTO=none
IPADDR0=10.66.192.101
PREFIX0=24
GATEWAY0=10.66.193.254
DEFROUTE=yes
DNS1=8.8.8.8
NAME="eth0"
DEVICE=eth0
ONBOOT=yes
UUID="c2f83f58-c273-46d9-a1cd-b29e434a2eea"
执行如下命令使静态地址生效
# nmcli connection reload
# nmcli connection down eth0
# nmcli connection up eth0

配置 node1

备份原始配置文件
# cd /etc/sysconfig/network-scripts/
# cp ifcfg-eth0 ifcfg-eth0-bak
编辑ifcfg-eth0,内容如下
BOOTPROTO=none
IPADDR0=10.66.192.102
PREFIX0=24
GATEWAY0=10.66.193.254
DEFROUTE=yes
DNS1=8.8.8.8
NAME="eth0"
DEVICE=eth0
ONBOOT=yes
UUID="0d7a5ff6-2491-4262-84a2-c1f629e40370"
执行如下命令使静态地址生效
# nmcli connection reload
# nmcli connection down eth0
# nmcli connection up eth0

配置 node2

备份原始配置文件
# cd /etc/sysconfig/network-scripts/
# cp ifcfg-eth0 ifcfg-eth0-bak
编辑ifcfg-eth0,内容如下
BOOTPROTO=none
IPADDR0=10.66.192.103
PREFIX0=24
GATEWAY0=10.66.193.254
DEFROUTE=yes
DNS1=8.8.8.8
NAME="eth0"
DEVICE=eth0
ONBOOT=yes
UUID="4d52c55b-01bc-40ae-9b9d-d5d903be2901"
执行如下命令使静态地址生效
# nmcli connection reload
# nmcli connection down eth0
# nmcli connection up eth0

测试配置

外部机器 ping master 和 node
$ ping -c2 10.66.192.101
PING 10.66.192.101 (10.66.192.101) 56(84) bytes of data.
64 bytes from 10.66.192.101: icmp_seq=1 ttl=64 time=0.575 ms
64 bytes from 10.66.192.101: icmp_seq=2 ttl=64 time=0.679 ms

--- 10.66.192.101 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1002ms
rtt min/avg/max/mdev = 0.575/0.627/0.679/0.052 ms

$ ping -c2 10.66.192.102
PING 10.66.192.102 (10.66.192.102) 56(84) bytes of data.
64 bytes from 10.66.192.102: icmp_seq=1 ttl=64 time=0.726 ms
64 bytes from 10.66.192.102: icmp_seq=2 ttl=64 time=0.708 ms

--- 10.66.192.102 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1004ms
rtt min/avg/max/mdev = 0.708/0.717/0.726/0.009 ms

$ ping -c2 10.66.192.103
PING 10.66.192.103 (10.66.192.103) 56(84) bytes of data.
64 bytes from 10.66.192.103: icmp_seq=1 ttl=64 time=0.800 ms
64 bytes from 10.66.192.103: icmp_seq=2 ttl=64 time=0.639 ms

--- 10.66.192.103 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1017ms
rtt min/avg/max/mdev = 0.639/0.719/0.800/0.084 ms
master ping node
# ping -c2 10.66.192.102
PING 10.66.192.102 (10.66.192.102) 56(84) bytes of data.
64 bytes from 10.66.192.102: icmp_seq=1 ttl=64 time=0.417 ms
64 bytes from 10.66.192.102: icmp_seq=2 ttl=64 time=0.223 ms

--- 10.66.192.102 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1000ms
rtt min/avg/max/mdev = 0.223/0.320/0.417/0.097 ms

# ping -c2 10.66.192.103
PING 10.66.192.103 (10.66.192.103) 56(84) bytes of data.
64 bytes from 10.66.192.103: icmp_seq=1 ttl=64 time=0.224 ms
64 bytes from 10.66.192.103: icmp_seq=2 ttl=64 time=0.353 ms

--- 10.66.192.103 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 999ms
rtt min/avg/max/mdev = 0.224/0.288/0.353/0.066 ms

results matching ""

    No results matching ""