端口

lsof

Linux查看端口的命令:
第一种:lsof -i:端口号
-a:显示本机所有连接和监听地端口
-n:网络IP地址的形式,显示当前建立的有效连接和端口
-r:显示路由表信息
-s:显示按协议的统计信息
-v:显示当前有效的连接
-t:显示所有TCP协议连接情况
-u:显示所有UDP协议连接情况
-i:显示自动配置端口的状态
-l:仅仅显示连接状态为listening的服务网络状态
-p:显示pid/program name
TCP连接的几种状态
ESTABLISHED 已建立
CLOSED 已关闭
LISTENING 正在监听
FIN-WAIT-2 等待连接关闭
TIME-WAIT 等待足够时间,确保服务器正常关闭该连接

防火墙

状态相关

  1. firewall-cmd --state 返回并打印防火墙状态
  2. firewall-cmd --reload Reload firewall and keep state information
  3. firewall-cmd --complete-reload Reload firewall and lose state information
  4. firewall-cmd --runtime-to-permanent
  5. Create permanent from runtime configuration
  6. firewall-cmd --check-config Check permanent configuration for errors

1、开启防火墙
systemctl start firewalld
2、开放指定端口
firewall-cmd —zone=public —add-port=1935/tcp —permanent
命令含义:
–zone #作用域
–add-port=1935/tcp #添加端口,格式为:端口/通讯协议
–permanent #永久生效,没有此参数重启后失效
3、重启防火墙
firewall-cmd —reload
关闭防火墙
systemctl stop firewalld
查看防火墙状态
systemctl status firewalld
firewall-cmd —state

查看服务器支持的所有服务

  1. firewall-cmd --get-serivces

查询外网端口是否放行

  1. firewall-cmd --query-port=8080/tcp

查询外网端口

  1. firewall-cmd --permanent --query-port=8080/tcp

查看端口号
netstat -ntlp //查看当前所有tcp端口·
netstat -ntulp |grep 1935 //查看所有1935端口使用情况·

帮助文档

  1. Usage: firewall-cmd [OPTIONS...]
  2. General Options
  3. -h, --help Prints a short help text and exists
  4. -V, --version Print the version string of firewalld
  5. -q, --quiet Do not print status messages
  6. Log Denied Options
  7. --get-log-denied Print the log denied value
  8. --set-log-denied=<value>
  9. Set log denied value
  10. Automatic Helpers Options
  11. --get-automatic-helpers
  12. Print the automatic helpers value
  13. --set-automatic-helpers=<value>
  14. Set automatic helpers value
  15. Permanent Options
  16. --permanent Set an option permanently
  17. Usable for options marked with [P]
  18. Zone Options
  19. --get-default-zone Print default zone for connections and interfaces
  20. --set-default-zone=<zone>
  21. Set default zone
  22. --get-active-zones Print currently active zones
  23. --get-zones Print predefined zones [P]
  24. --get-services Print predefined services [P]
  25. --get-icmptypes Print predefined icmptypes [P]
  26. --get-zone-of-interface=<interface>
  27. Print name of the zone the interface is bound to [P]
  28. --get-zone-of-source=<source>[/<mask>]|<MAC>|ipset:<ipset>
  29. Print name of the zone the source is bound to [P]
  30. --list-all-zones List everything added for or enabled in all zones [P]
  31. --new-zone=<zone> Add a new zone [P only]
  32. --new-zone-from-file=<filename> [--name=<zone>]
  33. Add a new zone from file with optional name [P only]
  34. --delete-zone=<zone> Delete an existing zone [P only]
  35. --load-zone-defaults=<zone>
  36. Load zone default settings [P only] [Z]
  37. --zone=<zone> Use this zone to set or query options, else default zone
  38. Usable for options marked with [Z]
  39. --get-target Get the zone target [P only] [Z]
  40. --set-target=<target>
  41. Set the zone target [P only] [Z]
  42. --info-zone=<zone> Print information about a zone
  43. --path-zone=<zone> Print file path of a zone [P only]
  44. IPSet Options
  45. --get-ipset-types Print the supported ipset types
  46. --new-ipset=<ipset> --type=<ipset type> [--option=<key>[=<value>]]..
  47. Add a new ipset [P only]
  48. --new-ipset-from-file=<filename> [--name=<ipset>]
  49. Add a new ipset from file with optional name [P only]
  50. --delete-ipset=<ipset>
  51. Delete an existing ipset [P only]
  52. --load-ipset-defaults=<ipset>
  53. Load ipset default settings [P only]
  54. --info-ipset=<ipset> Print information about an ipset
  55. --path-ipset=<ipset> Print file path of an ipset [P only]
  56. --get-ipsets Print predefined ipsets
  57. --ipset=<ipset> --set-description=<description>
  58. Set new description to ipset [P only]
  59. --ipset=<ipset> --get-description
  60. Print description for ipset [P only]
  61. --ipset=<ipset> --set-short=<description>
  62. Set new short description to ipset [P only]
  63. --ipset=<ipset> --get-short
  64. Print short description for ipset [P only]
  65. --ipset=<ipset> --add-entry=<entry>
  66. Add a new entry to an ipset [P]
  67. --ipset=<ipset> --remove-entry=<entry>
  68. Remove an entry from an ipset [P]
  69. --ipset=<ipset> --query-entry=<entry>
  70. Return whether ipset has an entry [P]
  71. --ipset=<ipset> --get-entries
  72. List entries of an ipset [P]
  73. --ipset=<ipset> --add-entries-from-file=<entry>
  74. Add a new entries to an ipset [P]
  75. --ipset=<ipset> --remove-entries-from-file=<entry>
  76. Remove entries from an ipset [P]
  77. IcmpType Options
  78. --new-icmptype=<icmptype>
  79. Add a new icmptype [P only]
  80. --new-icmptype-from-file=<filename> [--name=<icmptype>]
  81. Add a new icmptype from file with optional name [P only]
  82. --delete-icmptype=<icmptype>
  83. Delete an existing icmptype [P only]
  84. --load-icmptype-defaults=<icmptype>
  85. Load icmptype default settings [P only]
  86. --info-icmptype=<icmptype>
  87. Print information about an icmptype
  88. --path-icmptype=<icmptype>
  89. Print file path of an icmptype [P only]
  90. --icmptype=<icmptype> --set-description=<description>
  91. Set new description to icmptype [P only]
  92. --icmptype=<icmptype> --get-description
  93. Print description for icmptype [P only]
  94. --icmptype=<icmptype> --set-short=<description>
  95. Set new short description to icmptype [P only]
  96. --icmptype=<icmptype> --get-short
  97. Print short description for icmptype [P only]
  98. --icmptype=<icmptype> --add-destination=<ipv>
  99. Enable destination for ipv in icmptype [P only]
  100. --icmptype=<icmptype> --remove-destination=<ipv>
  101. Disable destination for ipv in icmptype [P only]
  102. --icmptype=<icmptype> --query-destination=<ipv>
  103. Return whether destination ipv is enabled in icmptype [P only]
  104. --icmptype=<icmptype> --get-destinations
  105. List destinations in icmptype [P only]
  106. Service Options
  107. --new-service=<service>
  108. Add a new service [P only]
  109. --new-service-from-file=<filename> [--name=<service>]
  110. Add a new service from file with optional name [P only]
  111. --delete-service=<service>
  112. Delete an existing service [P only]
  113. --load-service-defaults=<service>
  114. Load icmptype default settings [P only]
  115. --info-service=<service>
  116. Print information about a service
  117. --path-service=<service>
  118. Print file path of a service [P only]
  119. --service=<service> --set-description=<description>
  120. Set new description to service [P only]
  121. --service=<service> --get-description
  122. Print description for service [P only]
  123. --service=<service> --set-short=<description>
  124. Set new short description to service [P only]
  125. --service=<service> --get-short
  126. Print short description for service [P only]
  127. --service=<service> --add-port=<portid>[-<portid>]/<protocol>
  128. Add a new port to service [P only]
  129. --service=<service> --remove-port=<portid>[-<portid>]/<protocol>
  130. Remove a port from service [P only]
  131. --service=<service> --query-port=<portid>[-<portid>]/<protocol>
  132. Return whether the port has been added for service [P only]
  133. --service=<service> --get-ports
  134. List ports of service [P only]
  135. --service=<service> --add-protocol=<protocol>
  136. Add a new protocol to service [P only]
  137. --service=<service> --remove-protocol=<protocol>
  138. Remove a protocol from service [P only]
  139. --service=<service> --query-protocol=<protocol>
  140. Return whether the protocol has been added for service [P only]
  141. --service=<service> --get-protocols
  142. List protocols of service [P only]
  143. --service=<service> --add-source-port=<portid>[-<portid>]/<protocol>
  144. Add a new source port to service [P only]
  145. --service=<service> --remove-source-port=<portid>[-<portid>]/<protocol>
  146. Remove a source port from service [P only]
  147. --service=<service> --query-source-port=<portid>[-<portid>]/<protocol>
  148. Return whether the source port has been added for service [P only]
  149. --service=<service> --get-source-ports
  150. List source ports of service [P only]
  151. --service=<service> --add-module=<module>
  152. Add a new module to service [P only]
  153. --service=<service> --remove-module=<module>
  154. Remove a module from service [P only]
  155. --service=<service> --query-module=<module>
  156. Return whether the module has been added for service [P only]
  157. --service=<service> --get-modules
  158. List modules of service [P only]
  159. --service=<service> --set-destination=<ipv>:<address>[/<mask>]
  160. Set destination for ipv to address in service [P only]
  161. --service=<service> --remove-destination=<ipv>
  162. Disable destination for ipv i service [P only]
  163. --service=<service> --query-destination=<ipv>:<address>[/<mask>]
  164. Return whether destination ipv is set for service [P only]
  165. --service=<service> --get-destinations
  166. List destinations in service [P only]
  167. Options to Adapt and Query Zones
  168. --list-all List everything added for or enabled in a zone [P] [Z]
  169. --list-services List services added for a zone [P] [Z]
  170. --timeout=<timeval> Enable an option for timeval time, where timeval is
  171. a number followed by one of letters 's' or 'm' or 'h'
  172. Usable for options marked with [T]
  173. --set-description=<description>
  174. Set new description to zone [P only] [Z]
  175. --get-description Print description for zone [P only] [Z]
  176. --set-short=<description>
  177. Set new short description to zone [P only] [Z]
  178. --get-short Print short description for zone [P only] [Z]
  179. --add-service=<service>
  180. Add a service for a zone [P] [Z] [T]
  181. --remove-service=<service>
  182. Remove a service from a zone [P] [Z]
  183. --query-service=<service>
  184. Return whether service has been added for a zone [P] [Z]
  185. --list-ports List ports added for a zone [P] [Z]
  186. --add-port=<portid>[-<portid>]/<protocol>
  187. Add the port for a zone [P] [Z] [T]
  188. --remove-port=<portid>[-<portid>]/<protocol>
  189. Remove the port from a zone [P] [Z]
  190. --query-port=<portid>[-<portid>]/<protocol>
  191. Return whether the port has been added for zone [P] [Z]
  192. --list-protocols List protocols added for a zone [P] [Z]
  193. --add-protocol=<protocol>
  194. Add the protocol for a zone [P] [Z] [T]
  195. --remove-protocol=<protocol>
  196. Remove the protocol from a zone [P] [Z]
  197. --query-protocol=<protocol>
  198. Return whether the protocol has been added for zone [P] [Z]
  199. --list-source-ports List source ports added for a zone [P] [Z]
  200. --add-source-port=<portid>[-<portid>]/<protocol>
  201. Add the source port for a zone [P] [Z] [T]
  202. --remove-source-port=<portid>[-<portid>]/<protocol>
  203. Remove the source port from a zone [P] [Z]
  204. --query-source-port=<portid>[-<portid>]/<protocol>
  205. Return whether the source port has been added for zone [P] [Z]
  206. --list-icmp-blocks List Internet ICMP type blocks added for a zone [P] [Z]
  207. --add-icmp-block=<icmptype>
  208. Add an ICMP block for a zone [P] [Z] [T]
  209. --remove-icmp-block=<icmptype>
  210. Remove the ICMP block from a zone [P] [Z]
  211. --query-icmp-block=<icmptype>
  212. Return whether an ICMP block has been added for a zone
  213. [P] [Z]
  214. --add-icmp-block-inversion
  215. Enable inversion of icmp blocks for a zone [P] [Z]
  216. --remove-icmp-block-inversion
  217. Disable inversion of icmp blocks for a zone [P] [Z]
  218. --query-icmp-block-inversion
  219. Return whether inversion of icmp blocks has been enabled
  220. for a zone [P] [Z]
  221. --list-forward-ports List IPv4 forward ports added for a zone [P] [Z]
  222. --add-forward-port=port=<portid>[-<portid>]:proto=<protocol>[:toport=<portid>[-<portid>]][:toaddr=<address>[/<mask>]]
  223. Add the IPv4 forward port for a zone [P] [Z] [T]
  224. --remove-forward-port=port=<portid>[-<portid>]:proto=<protocol>[:toport=<portid>[-<portid>]][:toaddr=<address>[/<mask>]]
  225. Remove the IPv4 forward port from a zone [P] [Z]
  226. --query-forward-port=port=<portid>[-<portid>]:proto=<protocol>[:toport=<portid>[-<portid>]][:toaddr=<address>[/<mask>]]
  227. Return whether the IPv4 forward port has been added for
  228. a zone [P] [Z]
  229. --add-masquerade Enable IPv4 masquerade for a zone [P] [Z] [T]
  230. --remove-masquerade Disable IPv4 masquerade for a zone [P] [Z]
  231. --query-masquerade Return whether IPv4 masquerading has been enabled for a
  232. zone [P] [Z]
  233. --list-rich-rules List rich language rules added for a zone [P] [Z]
  234. --add-rich-rule=<rule>
  235. Add rich language rule 'rule' for a zone [P] [Z] [T]
  236. --remove-rich-rule=<rule>
  237. Remove rich language rule 'rule' from a zone [P] [Z]
  238. --query-rich-rule=<rule>
  239. Return whether a rich language rule 'rule' has been
  240. added for a zone [P] [Z]
  241. Options to Handle Bindings of Interfaces
  242. --list-interfaces List interfaces that are bound to a zone [P] [Z]
  243. --add-interface=<interface>
  244. Bind the <interface> to a zone [P] [Z]
  245. --change-interface=<interface>
  246. Change zone the <interface> is bound to [P] [Z]
  247. --query-interface=<interface>
  248. Query whether <interface> is bound to a zone [P] [Z]
  249. --remove-interface=<interface>
  250. Remove binding of <interface> from a zone [P] [Z]
  251. Options to Handle Bindings of Sources
  252. --list-sources List sources that are bound to a zone [P] [Z]
  253. --add-source=<source>[/<mask>]|<MAC>|ipset:<ipset>
  254. Bind the source to a zone [P] [Z]
  255. --change-source=<source>[/<mask>]|<MAC>|ipset:<ipset>
  256. Change zone the source is bound to [Z]
  257. --query-source=<source>[/<mask>]|<MAC>|ipset:<ipset>
  258. Query whether the source is bound to a zone [P] [Z]
  259. --remove-source=<source>[/<mask>]|<MAC>|ipset:<ipset>
  260. Remove binding of the source from a zone [P] [Z]
  261. Helper Options
  262. --new-helper=<helper> --module=<module> [--family=<family>]
  263. Add a new helper [P only]
  264. --new-helper-from-file=<filename> [--name=<helper>]
  265. Add a new helper from file with optional name [P only]
  266. --delete-helper=<helper>
  267. Delete an existing helper [P only]
  268. --load-helper-defaults=<helper>
  269. Load helper default settings [P only]
  270. --info-helper=<helper> Print information about an helper
  271. --path-helper=<helper> Print file path of an helper [P only]
  272. --get-helpers Print predefined helpers
  273. --helper=<helper> --set-description=<description>
  274. Set new description to helper [P only]
  275. --helper=<helper> --get-description
  276. Print description for helper [P only]
  277. --helper=<helper> --set-short=<description>
  278. Set new short description to helper [P only]
  279. --helper=<helper> --get-short
  280. Print short description for helper [P only]
  281. --helper=<helper> --add-port=<portid>[-<portid>]/<protocol>
  282. Add a new port to helper [P only]
  283. --helper=<helper> --remove-port=<portid>[-<portid>]/<protocol>
  284. Remove a port from helper [P only]
  285. --helper=<helper> --query-port=<portid>[-<portid>]/<protocol>
  286. Return whether the port has been added for helper [P only]
  287. --helper=<helper> --get-ports
  288. List ports of helper [P only]
  289. --helper=<helper> --set-module=<module>
  290. Set module to helper [P only]
  291. --helper=<helper> --get-module
  292. Get module from helper [P only]
  293. --helper=<helper> --set-family={ipv4|ipv6|}
  294. Set family for helper [P only]
  295. --helper=<helper> --get-family
  296. Get module from helper [P only]
  297. Direct Options
  298. --direct First option for all direct options
  299. --get-all-chains
  300. Get all chains [P]
  301. --get-chains {ipv4|ipv6|eb} <table>
  302. Get all chains added to the table [P]
  303. --add-chain {ipv4|ipv6|eb} <table> <chain>
  304. Add a new chain to the table [P]
  305. --remove-chain {ipv4|ipv6|eb} <table> <chain>
  306. Remove the chain from the table [P]
  307. --query-chain {ipv4|ipv6|eb} <table> <chain>
  308. Return whether the chain has been added to the table [P]
  309. --get-all-rules
  310. Get all rules [P]
  311. --get-rules {ipv4|ipv6|eb} <table> <chain>
  312. Get all rules added to chain in table [P]
  313. --add-rule {ipv4|ipv6|eb} <table> <chain> <priority> <arg>...
  314. Add rule to chain in table [P]
  315. --remove-rule {ipv4|ipv6|eb} <table> <chain> <priority> <arg>...
  316. Remove rule with priority from chain in table [P]
  317. --remove-rules {ipv4|ipv6|eb} <table> <chain>
  318. Remove rules from chain in table [P]
  319. --query-rule {ipv4|ipv6|eb} <table> <chain> <priority> <arg>...
  320. Return whether a rule with priority has been added to
  321. chain in table [P]
  322. --passthrough {ipv4|ipv6|eb} <arg>...
  323. Pass a command through (untracked by firewalld)
  324. --get-all-passthroughs
  325. Get all tracked passthrough rules [P]
  326. --get-passthroughs {ipv4|ipv6|eb} <arg>...
  327. Get tracked passthrough rules [P]
  328. --add-passthrough {ipv4|ipv6|eb} <arg>...
  329. Add a new tracked passthrough rule [P]
  330. --remove-passthrough {ipv4|ipv6|eb} <arg>...
  331. Remove a tracked passthrough rule [P]
  332. --query-passthrough {ipv4|ipv6|eb} <arg>...
  333. Return whether the tracked passthrough rule has been
  334. added [P]
  335. Lockdown Options
  336. --lockdown-on Enable lockdown.
  337. --lockdown-off Disable lockdown.
  338. --query-lockdown Query whether lockdown is enabled
  339. Lockdown Whitelist Options
  340. --list-lockdown-whitelist-commands
  341. List all command lines that are on the whitelist [P]
  342. --add-lockdown-whitelist-command=<command>
  343. Add the command to the whitelist [P]
  344. --remove-lockdown-whitelist-command=<command>
  345. Remove the command from the whitelist [P]
  346. --query-lockdown-whitelist-command=<command>
  347. Query whether the command is on the whitelist [P]
  348. --list-lockdown-whitelist-contexts
  349. List all contexts that are on the whitelist [P]
  350. --add-lockdown-whitelist-context=<context>
  351. Add the context context to the whitelist [P]
  352. --remove-lockdown-whitelist-context=<context>
  353. Remove the context from the whitelist [P]
  354. --query-lockdown-whitelist-context=<context>
  355. Query whether the context is on the whitelist [P]
  356. --list-lockdown-whitelist-uids
  357. List all user ids that are on the whitelist [P]
  358. --add-lockdown-whitelist-uid=<uid>
  359. Add the user id uid to the whitelist [P]
  360. --remove-lockdown-whitelist-uid=<uid>
  361. Remove the user id uid from the whitelist [P]
  362. --query-lockdown-whitelist-uid=<uid>
  363. Query whether the user id uid is on the whitelist [P]
  364. --list-lockdown-whitelist-users
  365. List all user names that are on the whitelist [P]
  366. --add-lockdown-whitelist-user=<user>
  367. Add the user name user to the whitelist [P]
  368. --remove-lockdown-whitelist-user=<user>
  369. Remove the user name user from the whitelist [P]
  370. --query-lockdown-whitelist-user=<user>
  371. Query whether the user name user is on the whitelist [P]
  372. Panic Options
  373. --panic-on Enable panic mode
  374. --panic-off Disable panic mode
  375. --query-panic Query whether panic mode is enabled