RH124-11 系统网络管理
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了RH124-11 系统网络管理相关的知识,希望对你有一定的参考价值。
第十一章 系统网络管理
11.1 网络基础概念
TCP/IP四层模型
应用层
传输层
定义了tcp和udp协议.应用程序通过使用tcp或udp协议定义的端口,来标识应用层协议.
常见协议对应的端口可参考/etc/services
firefox , ie ---> 百度:80
网络层
定义了IP协议,IP协议通过使用IP地址定位远程机器
链路层
偏向硬件的各种工业标准、协议
IP地址的组成
网络地址+主机地址
基础组网架构
IP路由: 默认网关
网卡的命名
传统的rhel系统以eth0,eth1等名字
来命名网卡,在rhel7系统开始使用新的命名规则:基于固件、设备结构、设备类型
1)由两个字母开头标示固件
以太网网卡以 en 开头
无线网卡以 wl 开头
2)设备结构
o 表示板载网卡(on-board)
s 热插拔结构(hotplug slot)
p PCI插槽位置
3)由一个数字表示设备的索引、ID或端口
如果网卡无法使用上述方法表示,则会选用传统方法ethN来表示
例子:
eno1 第一块板载网卡
enp2s0 第一块PCI插槽的网卡
11.2 测试和验证网络配置
$ ip addr show eth0
$ ip link
$ ip -s link show eth0 <--- -s 输出接口的状态
$ ip route 或 $ route -n
$ ping -c3 172.25.254.254
查看网络连接
$ ss -ta
-t tcp协议的连接
-a 所有状态的连接
-n 数字化输出
-u upd协议的连接
-l 处于listen状态的连接
-p 输出相应进程的名字
11.3 使用nmcli命令配置网络
NetworkManager是监控和管理网络设定的服务。该服务在GNOME桌面上有一个图形插件可以查看网络状态的。
他提供的命令行和图形配置工具对网络进行设定,设定保存的配置文件在/etc/sysconfig/network-scripts目录下。
机器的网卡通信需要配置IP,而IP可以通过DHCP自动获得,或者手工配置指定。
查看所有的连接(连接:NetworkManager定义的概念,由网卡设备和网卡的配置信息组成)
# nmcli con show
查看所有活动的连接
# nmcli con show --active
查看指定ID(name)连接的详细情况
# nmcli con show "System eth0"
查看设备状态
# nmcli dev status
查看指定设备的状态
# nmcli dev show eth0
使用nmcli创建新的连接:
1) 定一个名字为default的连接,该连接会通过DHCP自动配置
# nmcli con add con-name "default" type ethernet ifname eth
0
2)定一个名为static的连接,并且手工指定所配置的IP和网关,该连接不会自动激活(默认处于断开状态)
# nmcli con add con-name "static" ifname eth0 autoconnect no type
ethernet ip4 172.25.0.10/24 gw4 172.25.0.254
3)激活指定的名字为static的连接
# nmcli con up "static"
4)激活前面定义的default连接
# nmcli con up default
使用nmcli修改已有的网络连接:
1) 让连接取消自动激活
# nmcli con mod "static" connection.autoconnect no
2) 修改连接的dns
# nmcli con mod "static" ipv4.dns 172.25.0.254
3) 给连接再添加一个dns,有些设定值通过+/-可以增加或则移除设定
# nmcli con mod "static" +ipv4.dns 8.8.8.8
4) 替换连接的静态IP和默认网关
# nmcli con mod "static" ipv4.addresses "172.25.0.10/24 172.25.0.254"
5) 添加一个没有默认网关的IP
# nmcli con mod "static" +ipv4.addresses
10.10.10.10/16
6) 修改完毕,nmlci仅仅修改并保存了配置,要激活更改,需要重激活连接
# nmcli con up "static"
其余的一些用法:
# nmcli con del "<ID>"
# nmcli net off 关闭所有管
理的接口
# nmcli dev dis <DEV> 关闭某个接口,并临时禁用自动连接
# nmcli con down "<ID>" 断开某个连接
图形工具配置 nm-connection-editor
11.4 编辑网络配置文件
所有的连接定义的配置文件都在/etc/sysconfig/network-scripts/ifcfg-<name>中
需要掌握的选项:
静态配置 动态配置(DHCP)
两者都需要的配置
BOOTPROTO=none BOOTPROTO=dhcp DEVICE=eth0
IPADDR0=172.25.0.10 空 NAME="System eth0"
PREFIX0=24
空 ONBOOT=yes
GATEWAY0=172.25.0.254 空 UUID=f3e8dd32-3a2c
DEFROUTE=yes 空
USERCTL=yes
DNS1=172.25.254.254 空
选项说明:
某选项0,某选项1 代表该选项可以有多个设定值
DEFROUTE=yes 将接口设定为默认路由, no则否
USERCTL=yes 允许非root用户管理接口,no则否
手工编辑了配置文件,需要重载,才能生效
# nmcli con reload 重载配置文件
# nmcli con down "<name>" 关闭连接
# nmcli
con up "<name>" 激活连接
11.5 设定主机名和名字解析
查看主机名
# hostname
临时修改主机名
# hostname "somename"
在rhel7,静态主机名设定保存在/etc/hostname, 并且建议使用hostnamectl命令修改和查看系统
的FQDN主机名
# hostnamectl set-hostname desktop0.example.com
# hostnamectl status
# cat /etc/hostname
配置名字解析
名字解析可以通过DNS或者本机/etc/hosts实现。默认配置是先
hosts文件后查询DNS
指定dns地址 /etc/resolv.conf
------------------------------
11.1
[[email protected] Desktop]$ grep http /etc/services
# http://www.iana.org/assignments/port-numbers
http 80/tcp www www-http # WorldWideWeb HTTP
http 80/udp www www-http # HyperText Transfer Protocol
http 80/sctp # HyperText Transfer Protocol
https 443/tcp # http protocol over TLS/SSL
https 443/udp # http protocol over TLS/SSL
https 443/sctp # http protocol over TLS/SSL
gss-http 488/tcp
gss-http 488/udp
webcache 8080/tcp http-alt # WWW caching service
webcache 8080/udp http-alt # WWW caching service
http-mgmt 280/tcp # http-mgmt
http-mgmt 280/udp # http-mgmt
http-rpc-epmap 593/tcp # HTTP RPC Ep Map
http-rpc-epmap 593/udp # HTTP RPC Ep Map
11.2
flags=73<UP,LOOPBACK,RUNNING> mtu 65536
[[email protected] Desktop]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
ether 52:54:00:00:00:0a txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 50 bytes 8748 (8.5 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 0 (Local Loopback)
RX packets 8 bytes 556 (556.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 8 bytes 556 (556.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[[email protected] Desktop]# ip addr show eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 52:54:00:00:00:0a brd ff:ff:ff:ff:ff:ff
[[email protected] Desktop]# ip link
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000
link/ether 52:54:00:00:00:0a brd ff:ff:ff:ff:ff:ff
[[email protected] Desktop]# ip -s link s
set show
[[email protected] Desktop]# ip -s link show eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000
link/ether 52:54:00:00:00:0a brd ff:ff:ff:ff:ff:ff
RX: bytes packets errors dropped overrun mcast
684 2 0 0 0 0
TX: bytes packets errors dropped carrier collsns
46134 257 0 0 0 0
[[email protected] Desktop]# ip -s link show eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000
link/ether 52:54:00:00:00:0a brd ff:ff:ff:ff:ff:ff
RX: bytes packets errors dropped overrun mcast
31806 198 0 0 0 0
TX: bytes packets errors dropped carrier collsns
57079 366 0 0 0 0
[[email protected] Desktop]# ip route
default via 172.25.0.254 dev eth0 proto static metric 1024
172.25.0.0/24 dev eth0 proto kernel scope link src 172.25.0.10
172.25.253.254 via 172.25.0.254 dev eth0 proto static metric 1
[[email protected] Desktop]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 172.25.0.254 0.0.0.0 UG 1024 0 0 eth0
172.25.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
172.25.253.254 172.25.0.254 255.255.255.255 UGH 1 0 0 eth0
[[email protected] Desktop]#
[[email protected] Desktop]# ping -c3 172.25.254.254
PING 172.25.254.254 (172.25.254.254) 56(84) bytes of data.
64 bytes from 172.25.254.254: icmp_seq=1 ttl=64 time=0.553 ms
64 bytes from 172.25.254.254: icmp_seq=2 ttl=64 time=0.645 ms
64 bytes from 172.25.254.254: icmp_seq=3 ttl=64 time=0.731 ms
--- 172.25.254.254 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2004ms
rtt min/avg/max/mdev = 0.553/0.643/0.731/0.072 ms
[[email protected] Desktop]#
[[email protected] Desktop]# ss -tap
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 100 127.0.0.1:smtp *:* users:
(("master",1806,13))
LISTEN 0 128 *:sunrpc *:* users:
(("rpcbind",1516,9))
LISTEN 0 128 *:39601 *:* users:
(("rpc.statd",1587,9))
LISTEN 0 128 *:ssh *:* users:
(("sshd",1495,3))
LISTEN 0 128 127.0.0.1:ipp *:* users:
(("cupsd",2330,11))
LISTEN 0 100 ::1:smtp :::* users:
(("master",1806,14))
LISTEN 0 128 :::53862 :::* users:
(("rpc.statd",1587,11))
LISTEN 0 128 :::sunrpc :::* users:
(("rpcbind",1516,12))
LISTEN 0 128 :::ssh :::* users:
(("sshd",1495,4))
LISTEN 0 128 ::1:ipp :::* users:
(("cupsd",2330,10))
[[email protected] Desktop]# grep smtp /etc/services
smtp 25/tcp mail
smtp 25/udp mail
urd 465/tcp smtps # URL Rendesvous Directory for SSM / SMTP over SSL (TLS)
rsmtp 2390/tcp # RSMTP
rsmtp 2390/udp # RSMTP
[[email protected] Desktop]# ss -ta
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 100 127.0.0.1:smtp *:*
LISTEN 0 128 *:sunrpc *:*
LISTEN 0 128 *:39601 *:*
LISTEN 0 128 *:ssh *:*
LISTEN 0 128 127.0.0.1:ipp *:*
LISTEN 0 100 ::1:smtp :::*
LISTEN 0 128 :::53862 :::*
LISTEN 0 128 :::sunrpc :::*
LISTEN 0 128 :::ssh :::*
LISTEN 0 128 ::1:ipp :::*
=========================================================================================================
11.3
[[email protected] Desktop]# nm-connection-editor 调出图形界面
[[email protected] Desktop]# nmcli connection
add down help modify show
delete edit load reload up
[[email protected] Desktop]# nmcli connection show 查看所有接口
NAME UUID TYPE DEVICE
eth0 5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03 802-3-ethernet eth0
[[email protected] Desktop]# nmcli connection show "eth0"
connection.id: eth0
connection.uuid: 5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03
connection.interface-name: eth0
connection.type: 802-3-ethernet
connection.autoconnect: yes
connection.timestamp: 1496667151
connection.read-only: no
connection.permissions:
connection.zone: --
connection.master: --
connection.slave-type: --
connection.secondaries:
connection.gateway-ping-timeout: 0
802-3-ethernet.port: --
802-3-ethernet.speed: 0
802-3-ethernet.duplex: --
802-3-ethernet.auto-negotiate: yes
802-3-ethernet.mac-address: 52:54:00:00:00:0A
802-3-ethernet.cloned-mac-address: --
802-3-ethernet.mac-address-blacklist:
802-3-ethernet.mtu: auto
802-3-ethernet.s390-subchannels:
802-3-ethernet.s390-nettype: --
802-3-ethernet.s390-options:
ipv4.method: auto
ipv4.dns:
ipv4.dns-search:
ipv4.addresses:
ipv4.routes:
ipv4.ignore-auto-routes: no
ipv4.ignore-auto-dns: no
ipv4.dhcp-client-id: --
ipv4.dhcp-send-hostname: yes
ipv4.dhcp-hostname: --
ipv4.never-default: no
ipv4.may-fail: yes
ipv6.method: ignore
ipv6.dns:
ipv6.dns-search:
ipv6.addresses:
ipv6.routes:
ipv6.ignore-auto-routes: no
ipv6.ignore-auto-dns: no
ipv6.never-default: no
ipv6.may-fail: yes
ipv6.ip6-privacy: -1 (unknown)
ipv6.dhcp-hostname: --
GENERAL.NAME: eth0
GENERAL.UUID: 5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03
GENERAL.DEVICES: eth0
GENERAL.STATE: activated
GENERAL.DEFAULT: yes
GENERAL.DEFAULT6: no
GENERAL.VPN: no
GENERAL.ZONE: --
GENERAL.DBUS-PATH: /org/freedesktop/NetworkManager/ActiveConnection/20
GENERAL.CON-PATH: /org/freedesktop/NetworkManager/Settings/0
GENERAL.SPEC-OBJECT: --
GENERAL.MASTER-PATH: --
IP4.ADDRESS[1]: ip = 172.25.0.10/24, gw = 172.25.0.254
IP4.ROUTE[1]: dst = 172.25.253.254/32, nh = 172.25.0.254, mt = 0
IP4.DNS[1]: 172.25.254.254
IP4.DOMAIN[1]: example.com
DHCP4.OPTION[1]: requested_domain_search = 1
DHCP4.OPTION[2]: dhcp_message_type = 5
DHCP4.OPTION[3]: requested_time_offset = 1
DHCP4.OPTION[4]: requested_domain_name = 1
DHCP4.OPTION[5]: requested_rfc3442_classless_static_routes = 1
DHCP4.OPTION[6]: requested_broadcast_address = 1
DHCP4.OPTION[7]: requested_classless_static_routes = 1
DHCP4.OPTION[8]: expiry = 1496688191
DHCP4.OPTION[9]: domain_name = example.com
DHCP4.OPTION[10]: next_server = 172.25.0.254
DHCP4.OPTION[11]: broadcast_address = 172.25.0.255
DHCP4.OPTION[12]: requested_interface_mtu = 1
DHCP4.OPTION[13]: requested_subnet_mask = 1
DHCP4.OPTION[14]: dhcp_lease_time = 21600
DHCP4.OPTION[15]: ip_address = 172.25.0.10
DHCP4.OPTION[16]: requested_nis_domain = 1
DHCP4.OPTION[17]: routers = 172.25.0.254
DHCP4.OPTION[18]: requested_wpad = 1
DHCP4.OPTION[19]: requested_static_routes = 1
DHCP4.OPTION[20]: requested_nis_servers = 1
DHCP4.OPTION[21]: domain_name_servers = 172.25.254.254
DHCP4.OPTION[22]: requested_domain_name_servers = 1
DHCP4.OPTION[23]: requested_ntp_servers = 1
DHCP4.OPTION[24]: requested_routers = 1
DHCP4.OPTION[25]: requested_ms_classless_static_routes = 1
DHCP4.OPTION[26]: subnet_mask = 255.255.255.0
DHCP4.OPTION[27]: requested_host_name = 1
DHCP4.OPTION[28]: network_number = 172.25.0.0
DHCP4.OPTION[29]: dhcp_server_identifier = 172.25.253.254
IP6.ADDRESS[1]: ip = fe80::5054:ff:fe00:a/64, gw = ::
查看实际的网卡设备 :
[[email protected] Desktop]# nmcli dev status
DEVICE TYPE STATE CONNECTION
eth0 ethernet disconnected --
lo loopback unmanaged --
扩展:
[[email protected] Desktop]# ip -s link show eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000
link/ether 52:54:00:00:00:0a brd ff:ff:ff:ff:ff:ff
RX: bytes packets errors dropped overrun mcast
0 0 0 0 0 0
TX: bytes packets errors dropped carrier collsns
17838 101 0 0 0 0
[[email protected] Desktop]# ifconfig eth0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.25.0.10 netmask 255.255.255.0 broadcast 172.25.0.255
inet6 fe80::5054:ff:fe00:a prefixlen 64 scopeid 0x20<link>
ether 52:54:00:00:00:0a txqueuelen 1000 (Ethernet)
RX packets 154 bytes 26774 (26.1 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 171 bytes 25799 (25.1 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[[email protected] Desktop]#
新加一个连接:给一个网卡配置 信息
[[email protected] Desktop]# nmcli connection add con-name "default" ifname
eth0 lo
[[email protected] Desktop]# nmcli connection add con-name "default" type ethernet ifname eth0
Connection ‘default‘ (fdd301e7-e38e-4a77-8bb5-03b0bf060879) successfully added.
[[email protected] Desktop]# nmcli connection show
NAME UUID TYPE DEVICE
default fdd301e7-e38e-4a77-8bb5-03b0bf060879 802-3-ethernet --
eth0 5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03 802-3-ethernet eth0
cloned-mac gw4 gw6 ip4 ip6 mac mtu save
[[email protected] Desktop]# nmcli con add con-name "static" ifname eth0 type ethernet autoconnect yes ip4 172.25.0.10/24
gw4 gw6 ip6
[[email protected] Desktop]# nmcli con add con-name "static" ifname eth0 type ethernet autoconnect yes ip4 172.25.0.10/24 gw4 172.25.0.254
Connection ‘static‘ (b09adbe1-8632-4f50-96eb-4a7893adbe9b) successfully added.
[[email protected] Desktop]#
[[email protected] Desktop]#
[[email protected] Desktop]#
[[email protected] Desktop]# nmcli connection show
NAME UUID TYPE DEVICE
static a83fb9b4-cf8f-48c8-b506-7b39992deac6 802-3-ethernet --
default fdd301e7-e38e-4a77-8bb5-03b0bf060879 802-3-ethernet --
eth0 5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03 802-3-ethernet eth0
static b09adbe1-8632-4f50-96eb-4a7893adbe9b 802-3-ethernet --
[[email protected] Desktop]#
[[email protected] Desktop]# nmcli connection up static 启用某个连接
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/21)
[[email protected] Desktop]# nmcli connection show 一个物理设备 只能给一个逻辑NAME 用。
NAME UUID TYPE DEVICE
static a83fb9b4-cf8f-48c8-b506-7b39992deac6 802-3-ethernet eth0
default fdd301e7-e38e-4a77-8bb5-03b0bf060879 802-3-ethernet --
eth0 5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03 802-3-ethernet --
static b09adbe1-8632-4f50-96eb-4a7893adbe9b 802-3-ethernet --
[[email protected] Desktop]# ls /etc/sysconfig/network-scripts/ifcfg-*
/etc/sysconfig/network-scripts/ifcfg-default /etc/sysconfig/network-scripts/ifcfg-lo /etc/sysconfig/network-scripts/ifcfg-static-1
/etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-static
[[email protected] Desktop]#
n
localhost Desktop]# nmcli connection modify static connection.autoconnect no 服务启动后配置不启动
[[email protected] Desktop]# nmcli connection modify static ipv4.dns 172.25.0.254 加入DNS配置
[email protected] Desktop]#
nmcli con add con-name "static" ifname eth0 type ethernet autoconnect yes ip4 172.25.0.10/24 gw4 172.25.0.254
Connection ‘static‘ (c665c0e9-982f-4393-a1f8-673ec7c60c3d) successfully added.
[[email protected] Desktop]# nmcli connection up static 让配置 生效
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/23)
[[email protected] Desktop]# nmci co sh
bash: nmci: command not found...
[[email protected] Desktop]# nmcli co sh
NAME UUID TYPE DEVICE
static a83fb9b4-cf8f-48c8-b506-7b39992deac6 802-3-ethernet eth0
default fdd301e7-e38e-4a77-8bb5-03b0bf060879 802-3-ethernet --
eth0 5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03 802-3-ethernet --
static c665c0e9-982f-4393-a1f8-673ec7c60c3d 802-3-ethernet --
static b09adbe1-8632-4f50-96eb-4a7893adbe9b 802-3-ethernet --
[[email protected] Desktop]#
删除配置 :
[[email protected] Desktop]# ^C
[[email protected] Desktop]# nmcli co delete default
[[email protected] Desktop]# nmcli co delete static
[[email protected] Desktop]# nmcli co show
NAME UUID TYPE DEVICE
eth0 5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03 802-3-ethernet eth0
[[email protected] Desktop]#
11.4
[[email protected] Desktop]# ls /etc/sysconfig/network-scripts/ifcfg-*
/etc/sysconfig/network-scripts/ifcfg-eth0
/etc/sysconfig/network-scripts/ifcfg-Ethernet_connection_1
/etc/sysconfig/network-scripts/ifcfg-lo
[[email protected] Desktop]# nmcli connection show
NAME UUID TYPE DEVICE
Ethernet connection 1 cbed67a1-6d16-44e6-815d-3e3554ee1b93 802-3-ethernet --
eth0 5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03 802-3-ethernet eth0
[[email protected] Desktop]# nmcli connection delete static
Error: unknown connection: static
Error: cannot delete unknown connection(s): ‘static‘.
[[email protected] Desktop]# nmcli connection add con-name static type ethernet autoconnect yes ifname eth0 ip4 172.25.0.10/24 gw4 172.25.0.254
Connection ‘static‘ (69b5c248-5aeb-4dda-bed2-6ff176103091) successfully added.
[[email protected] Desktop]#
[[email protected] Desktop]# ls /etc/sysconfig/network-scripts/ifcfg-static
/etc/sysconfig/network-scripts/ifcfg-static
[[email protected] Desktop]# vim !$
nmcli con reload重新加载一下才可以看见IP地址 nmcli con show eht0。
nmcli connection up static 再UP才可以查看ip addr show eth0
改了IP后,需要nmcli con down static ,再nmcli con up static
11,5
nmcli connection up static 临时生效
[[email protected] Desktop]# hostnamectl
Static hostname: n/a
Transient hostname: test.exmaple.com
Icon name: computer
Chassis: n/a
Machine ID: 946cb0e817ea4adb916183df8c4fc817
Boot ID: 42db5671e6e04410bf54573cd265ffa9
Virtualization: vmware
Operating System: Red Hat Enterprise Linux Server 7.0 (Maipo)
CPE OS Name: cpe:/o:redhat:enterprise_linux:7.0:GA:server
Kernel: Linux 3.10.0-123.el7.x86_64
Architecture: x86_64
[[email protected] Desktop]#
静态主机名:
[[email protected] Desktop]# hostnamectl
Static hostname: n/a
Transient hostname: test.exmaple.com
Icon name: computer
Chassis: n/a
Machine ID: 946cb0e817ea4adb916183df8c4fc817
Boot ID: 42db5671e6e04410bf54573cd265ffa9
Virtualization: vmware
Operating System: Red Hat Enterprise Linux Server 7.0 (Maipo)
CPE OS Name: cpe:/o:redhat:enterprise_linux:7.0:GA:server
Kernel: Linux 3.10.0-123.el7.x86_64
Architecture: x86_64
[[email protected] Desktop]#
改配置文件
[[email protected] Desktop]# cat /etc/hostname
test.exmaple.com
[[email protected] Desktop]# vim !$ 这样改后重启还是不生效
vim /etc/hostname
[[email protected] Desktop]# cat /etc/hostname
test9.exmaple.com
hostnamectl set-
hostname desktop0.example.com 最好是用这个命令
加DNS:
[[email protected] Desktop]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
172.25.254.254 classroom.example.com
172.25.254.254 content.example.com
[[email protected] Desktop]#
[[email protected] Desktop]#
[[email protected] Desktop]# vim !$ 进去加一个映射:172.25.0.10 desktop0.example.com
vim /etc/hosts
[[email protected] Desktop]# ping -c1 desktop0.example.com
PING desktop0.example.com (172.25.0.10) 56(84) bytes of data.
64 bytes from desktop0.example.com (172.25.0.10): icmp_seq=1 ttl=64 time=0.714 ms
--- desktop0.example.com ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.714/0.714/0.714/0.000 ms
[[email protected] Desktop]#
加IP 网关,DNS1,DNS2
[email protected] Desktop]# nmcli connection add con-name static type ethernet autoconnect yes ifname eth0 ip4 172.25.0.10/24 gw4 172.25.0.254
Connection ‘static‘ (d5852f05-17a1-43c6-b46a-2946f9186609) successfully added.
[[email protected] Desktop]#
[[email protected] Desktop]# nmcli co mo static ipv4.dns 172.25.0.254
[[email protected] Desktop]#
[[email protected] Desktop]# vim /etc/resolv.conf
[[email protected] Desktop]# nmcli co mo static ipv4.dns 8.8.8.8
[[email protected] Desktop]# vim /etc/resolv.conf
[[email protected] Desktop]# vim /etc/resolv.conf
[[email protected] Desktop]# nmcli co up static
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/5)
[[email protected] Desktop]# cat /etc/resolv.conf
# Generated by NetworkManager
search example.com
nameserver 8.8.8.8
[[email protected] Desktop]# nmcli co mo static +ipv4.dns 172.25.0.254
[[email protected] Desktop]# nmcli co up static
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/6)
[[email protected] Desktop]# cat /etc/resolv.conf
# Generated by NetworkManager
search example.com
nameserver 8.8.8.8
nameserver 172.25.0.254
[email protected] Desktop]# cat /etc/resolv.conf
# Generated by NetworkManager
search example.com
nameserver 8.8.8.8
nameserver 172.25.0.254
[[email protected] Desktop]# vi !$ 进去配置
vi /etc/resolv.conf
# Generated by NetworkManager
search example.com
nameserver 114.114.114.114
nameserver 8.8.8.8
nameserver 172.25.0.254
~ 最多可以指定三个
[[email protected] Desktop]# nmcli co dow static
[[email protected] Desktop]# nmcli co show
NAME UUID TYPE DEVICE
static 69b5c248-5aeb-4dda-bed2-6ff176103091 802-3-ethernet --
Ethernet connection 1 cbed67a1-6d16-44e6-815d-3e3554ee1b93 802-3-ethernet --
eth0 5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03 802-3-ethernet eth0
static d5852f05-17a1-43c6-b46a-2946f9186609 802-3-ethernet --
static 1ec9d5f6-c441-464c-95b9-ab14894e6bf8 802-3-ethernet --
[[email protected] Desktop]# cat /etc/resolv.conf 再次查看发现变了,原因是每个连接口的nameserver是不一样的
# Generated by NetworkManager
domain example.com
search example.com
nameserver 172.25.254.254
[[email protected] Desktop]#
本文出自 “HCIE_38xx” 博客,谢绝转载!
以上是关于RH124-11 系统网络管理的主要内容,如果未能解决你的问题,请参考以下文章