34.2. 使用 nmstatectl 配置带有 802.1X 网络身份验证的静态以太网连接
您可以使用声明性 Nmstate API 来配置带有 802.1X 网络身份验证的以太网连接。nmstate 可确保结果与配置文件匹配或回滚更改。
注意
nmstate 库只支持 TLS 可扩展身份验证协议(EAP)方法。
先决条件
- 网络支持 802.1X 网络身份验证。
- 受管节点使用 NetworkManager。
客户端上存在 TLS 身份验证所需的以下文件:
-
存储的客户端密钥位于
/etc/pki/tls/private/client.key文件中,该文件归root用户所有,且只对 root 可读。 -
客户端证书存储在
/etc/pki/tls/certs/client.crt文件中。 -
证书颁发机构(CA)证书存储在
/etc/pki/tls/certs/ca.crt文件中。
-
存储的客户端密钥位于
流程
创建包含以下内容的 YAML 文件,如
~/create-ethernet-profile.yml:--- interfaces: - name: enp1s0 type: ethernet state: up ipv4: enabled: true address: - ip: 192.0.2.1 prefix-length: 24 dhcp: false ipv6: enabled: true address: - ip: 2001:db8:1::1 prefix-length: 64 autoconf: false dhcp: false 802.1x: ca-cert: /etc/pki/tls/certs/ca.crt client-cert: /etc/pki/tls/certs/client.crt eap-methods: - tls identity: client.example.org private-key: /etc/pki/tls/private/client.key private-key-password: password routes: config: - destination: 0.0.0.0/0 next-hop-address: 192.0.2.254 next-hop-interface: enp1s0 - destination: ::/0 next-hop-address: 2001:db8:1::fffe next-hop-interface: enp1s0 dns-resolver: config: search: - example.com server: - 192.0.2.200 - 2001:db8:1::ffbb这些设置使用以下设置为
enp1s0设备定义一个以太网连接配置文件:-
静态 IPv4 地址 -
192.0.2.1和/24子网掩码 -
静态 IPv6 地址 -
2001:db8:1::1和/64子网掩码 -
IPv4 默认网关 -
192.0.2.254 -
IPv6 默认网关 -
2001:db8:1::fffe -
IPv4 DNS 服务器 -
192.0.2.200 -
IPv6 DNS 服务器 -
2001:db8:1::ffbb -
DNS 搜索域 -
example.com -
使用
TLSEAP 协议的 802.1x 网络身份验证
-
静态 IPv4 地址 -
将设置应用到系统:
# nmstatectl apply ~/create-ethernet-profile.yml
验证
- 访问需要网络身份验证的网络上的资源。