文章目录
-
- 2.1 SaltStack常用模块之network
-
- 2.1.1 network.active_tcp
- 2.1.2 network.calc_net
- 2.1.3 network.connect
- 2.1.4 network.default_route
- 2.1.5 network.get_fqdn
- 2.1.7 network.get_route
- 2.1.8 network.hw_addr
- 2.1.9 network.ifacestartswith
- 2.1.10 network.in_subnet
- 2.1.11 network.interface
- 2.1.12 network.interface_ip
- 2.1.13 network.interfaces
- 2.1.14 network.ip_addrs
- 2.1.15 network.netstat
- 2.1.16 network.ping
- 2.1.17 network.reverse_ip
- 2.2 SaltStack常用模块之service
- 2.3 SaltStack常用模块之pkg
2.1 SaltStack常用模块之network
2.1.1 network.active_tcp
返回所有tcp连接
node1:
----------
0:
----------
local_addr:
0.0.0.0
local_port:
22
remote_addr:
0.0.0.0
remote_port:
0
1:
----------
local_addr:
0.0.0.0
local_port:
4505
remote_addr:
0.0.0.0
remote_port:
0
10:
----------
local_addr:
192.168.220.10
local_port:
33270
remote_addr:
192.168.220.10
remote_port:
4506
11:
----------
local_addr:
127.0.0.1
local_port:
47714
remote_addr:
127.0.0.1
remote_port:
4506
12:
----------
local_addr:
192.168.220.10
local_port:
4505
remote_addr:
192.168.220.30
remote_port:
38894
13:
----------
local_addr:
192.168.220.10
local_port:
4506
remote_addr:
192.168.220.10
remote_port:
33270
14:
----------
local_addr:
192.168.220.10
local_port:
4506
remote_addr:
192.168.220.30
remote_port:
57468
15:
----------
local_addr:
192.168.220.10
local_port:
22
remote_addr:
192.168.220.1
remote_port:
54526
2:
----------
local_addr:
127.0.0.1
local_port:
25
remote_addr:
0.0.0.0
remote_port:
0
3:
----------
local_addr:
0.0.0.0
local_port:
4506
remote_addr:
0.0.0.0
remote_port:
0
4:
----------
local_addr:
192.168.220.10
local_port:
22
remote_addr:
192.168.220.1
remote_port:
59734
5:
----------
local_addr:
192.168.220.10
local_port:
4506
remote_addr:
192.168.220.30
remote_port:
49114
6:
----------
local_addr:
192.168.220.10
local_port:
60916
remote_addr:
192.168.220.10
remote_port:
4505
7:
----------
local_addr:
192.168.220.10
local_port:
4505
remote_addr:
192.168.220.10
remote_port:
60916
8:
----------
local_addr:
127.0.0.1
local_port:
47718
remote_addr:
127.0.0.1
remote_port:
4506
9:
----------
local_addr:
192.168.220.10
local_port:
33304
remote_addr:
192.168.220.10
remote_port:
4506
[root@node1 ~]# lsof -ni:22
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
sshd 1021 root 3u IPv4 19985 0t0 TCP *:ssh (LISTEN)
sshd 1021 root 4u IPv6 19987 0t0 TCP *:ssh (LISTEN)
sshd 4297 root 3u IPv4 76879 0t0 TCP 192.168.220.10:ssh->192.168.220.1:59734 (ESTABLISHED)
sshd 10453 root 3u IPv4 131595 0t0 TCP 192.168.220.10:ssh->192.168.220.1:54526 (ESTABLISHED)
2.1.2 network.calc_net
通过IP和子网掩码计算出网段
alt '*' network.calc_net 192.168.220.10 255.255.255.0
192.168.220.10:
192.168.220.0/24
2.1.3 network.connect
测试minion至某一台服务器的网络是否连通
[root@node1 yum.repos.d]# salt '*' network.connect baidu.com 80
node1:
----------
comment:
Successfully connected to baidu.com (39.156.69.79) on tcp port 80
result:
True
node02:
----------
comment:
Successfully connected to baidu.com (39.156.69.79) on tcp port 80
result:
True
2.1.4 network.default_route
查看默认路由
[root@node1 yum.repos.d]# salt '*' network.default_route
node1:
|_
----------
addr_family:
inet
destination:
0.0.0.0
flags:
UG
gateway:
192.168.220.2
interface:
ens33
netmask:
0.0.0.0
|_
----------
addr_family:
inet6
destination:
::/0
flags:
-1
gateway:
::
interface:
lo
netmask:
|_
----------
addr_family:
inet6
destination:
::/0
flags:
-1
gateway:
::
interface:
lo
netmask:
node02:
|_
----------
addr_family:
inet
destination:
0.0.0.0
flags:
UG
gateway:
192.168.220.2
interface:
ens33
netmask:
0.0.0.0
|_
----------
addr_family:
inet6
destination:
::/0
flags:
-1
gateway:
::
interface:
lo
netmask:
|_
----------
addr_family:
inet6
destination:
::/0
flags:
-1
gateway:
::
interface:
lo
netmask:
2.1.5 network.get_fqdn
查看主机的fqdn(完全限定域名)
[root@master ~]# salt '*' network.get_hostname
192.168.220.10:
node1
192.168.220.30:
node02
2.1.7 network.get_route
查询到一个目标网络的路由信息
[root@node1 yum.repos.d]# salt '*' network.get_route 192.168.220.10
node1:
----------
destination:
192.168.220.10
gateway:
None
interface:
lo
source:
192.168.220.10
node02:
----------
destination:
192.168.220.10
gateway:
None
interface:
ens33
source:
192.168.220.30
2.1.8 network.hw_addr
返回指定网卡的MAC地址
[root@node1 yum.repos.d]# salt '*' network.hw_addr ens33
node1:
00:0c:29:a0:77:bd
node02:
00:0c:29:45:ba:a4
2.1.9 network.ifacestartswith
从特定CIDR检索接口名称
2.1.10 network.in_subnet
判断当前主机是否在某一个网段内
[root@node1 yum.repos.d]# salt '*' network.in_subnet 192.168.220.0/24
node1:
True
node02:
True
2.1.11 network.interface
返回指定网卡的信息
[root@node1 yum.repos.d]# salt '*' network.interface ens33
node1:
|_
----