c62f803c.html 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604
  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
  6. <meta name="theme-color" content="#222">
  7. <meta name="generator" content="Hexo 5.4.0">
  8. <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  9. <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  10. <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  11. <link rel="mask-icon" href="/images/safari-pinned-tab.svg" color="#222">
  12. <meta name="google-site-verification" content="cCGIgodGvlMoVATcXs4p7kl8BVhmqW8u1kcPBZfD2qw">
  13. <link rel="stylesheet" href="/css/main.css">
  14. <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&display=swap&subset=latin,latin-ext">
  15. <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.15.2/css/all.min.css">
  16. <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/animate.css@3.1.1/animate.min.css">
  17. <script class="hexo-configurations">
  18. var NexT = window.NexT || {};
  19. var CONFIG = {"hostname":"blog.izhixing.icu","root":"/","images":"/images","scheme":"Gemini","version":"8.2.2","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12},"copycode":false,"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"prism":false,"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果:${query}","hits_time":"找到 ${hits} 个搜索结果(用时 ${time} 毫秒)","hits":"找到 ${hits} 个搜索结果"},"path":"/search.xml","localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false}};
  20. </script>
  21. <meta name="description" content="新装的Linux系统,ssh、nginx、tomcat等各种服务都安装好了,可是在外网却访问不了??这十有八九是防火墙的端口没有打开了。">
  22. <meta property="og:type" content="article">
  23. <meta property="og:title" content="Linux操作指南:02-配置防火墙端口">
  24. <meta property="og:url" content="https://blog.izhixing.icu/posts/c62f803c.html">
  25. <meta property="og:site_name" content="知行">
  26. <meta property="og:description" content="新装的Linux系统,ssh、nginx、tomcat等各种服务都安装好了,可是在外网却访问不了??这十有八九是防火墙的端口没有打开了。">
  27. <meta property="og:locale" content="zh_CN">
  28. <meta property="article:published_time" content="2021-03-27T13:10:14.000Z">
  29. <meta property="article:modified_time" content="2021-04-06T14:39:44.492Z">
  30. <meta property="article:author" content="知行">
  31. <meta property="article:tag" content="Linux">
  32. <meta name="twitter:card" content="summary">
  33. <link rel="canonical" href="https://blog.izhixing.icu/posts/c62f803c.html">
  34. <script class="page-configurations">
  35. // https://hexo.io/docs/variables.html
  36. CONFIG.page = {
  37. sidebar: "",
  38. isHome : false,
  39. isPost : true,
  40. lang : 'zh-CN'
  41. };
  42. </script>
  43. <title>Linux操作指南:02-配置防火墙端口 | 知行</title>
  44. <script async src="https://www.googletagmanager.com/gtag/js?id=UA-135887327-1"></script>
  45. <script>
  46. if (CONFIG.hostname === location.hostname) {
  47. window.dataLayer = window.dataLayer || [];
  48. function gtag(){dataLayer.push(arguments);}
  49. gtag('js', new Date());
  50. gtag('config', 'UA-135887327-1');
  51. }
  52. </script>
  53. <noscript>
  54. <style>
  55. body { margin-top: 2rem; }
  56. .use-motion .menu-item,
  57. .use-motion .sidebar,
  58. .use-motion .post-block,
  59. .use-motion .pagination,
  60. .use-motion .comments,
  61. .use-motion .post-header,
  62. .use-motion .post-body,
  63. .use-motion .collection-header {
  64. visibility: visible;
  65. }
  66. .use-motion .header,
  67. .use-motion .site-brand-container .toggle,
  68. .use-motion .footer { opacity: initial; }
  69. .use-motion .site-title,
  70. .use-motion .site-subtitle,
  71. .use-motion .custom-logo-image {
  72. opacity: initial;
  73. top: initial;
  74. }
  75. .use-motion .logo-line {
  76. transform: scaleX(1);
  77. }
  78. .search-pop-overlay, .sidebar-nav { display: none; }
  79. .sidebar-panel { display: block; }
  80. </style>
  81. </noscript>
  82. </head>
  83. <body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  84. <div class="headband"></div>
  85. <main class="main">
  86. <header class="header" itemscope itemtype="http://schema.org/WPHeader">
  87. <div class="header-inner"><div class="site-brand-container">
  88. <div class="site-nav-toggle">
  89. <div class="toggle" aria-label="切换导航栏" role="button">
  90. <span class="toggle-line"></span>
  91. <span class="toggle-line"></span>
  92. <span class="toggle-line"></span>
  93. </div>
  94. </div>
  95. <div class="site-meta">
  96. <a href="/" class="brand" rel="start">
  97. <i class="logo-line"></i>
  98. <h1 class="site-title">知行</h1>
  99. <i class="logo-line"></i>
  100. </a>
  101. </div>
  102. <div class="site-nav-right">
  103. <div class="toggle popup-trigger">
  104. <i class="fa fa-search fa-fw fa-lg"></i>
  105. </div>
  106. </div>
  107. </div>
  108. <nav class="site-nav">
  109. <ul class="main-menu menu">
  110. <li class="menu-item menu-item-home"><a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a></li>
  111. <li class="menu-item menu-item-tags"><a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签</a></li>
  112. <li class="menu-item menu-item-categories"><a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a></li>
  113. <li class="menu-item menu-item-archives"><a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a></li>
  114. <li class="menu-item menu-item-sitemap"><a href="/sitemap.xml" rel="section"><i class="fa fa-sitemap fa-fw"></i>站点地图</a></li>
  115. <li class="menu-item menu-item-search">
  116. <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
  117. </a>
  118. </li>
  119. </ul>
  120. </nav>
  121. <div class="search-pop-overlay">
  122. <div class="popup search-popup"><div class="search-header">
  123. <span class="search-icon">
  124. <i class="fa fa-search"></i>
  125. </span>
  126. <div class="search-input-container">
  127. <input autocomplete="off" autocapitalize="off" maxlength="80"
  128. placeholder="搜索..." spellcheck="false"
  129. type="search" class="search-input">
  130. </div>
  131. <span class="popup-btn-close" role="button">
  132. <i class="fa fa-times-circle"></i>
  133. </span>
  134. </div>
  135. <div class="search-result-container no-result">
  136. <div class="search-result-icon">
  137. <i class="fa fa-spinner fa-pulse fa-5x"></i>
  138. </div>
  139. </div>
  140. </div>
  141. </div>
  142. </div>
  143. <div class="toggle sidebar-toggle" role="button">
  144. <span class="toggle-line"></span>
  145. <span class="toggle-line"></span>
  146. <span class="toggle-line"></span>
  147. </div>
  148. <aside class="sidebar">
  149. <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
  150. <ul class="sidebar-nav">
  151. <li class="sidebar-nav-toc">
  152. 文章目录
  153. </li>
  154. <li class="sidebar-nav-overview">
  155. 站点概览
  156. </li>
  157. </ul>
  158. <div class="sidebar-panel-container">
  159. <!--noindex-->
  160. <div class="post-toc-wrap sidebar-panel">
  161. <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#%E7%8E%AF%E5%A2%83"><span class="nav-number">1.</span> <span class="nav-text">环境</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#firewall-cmd%E4%B8%8Eiptables"><span class="nav-number">2.</span> <span class="nav-text">firewall-cmd与iptables</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E7%AB%AF%E5%8F%A3%E5%BC%80%E5%8F%91%E7%9A%84%E4%B8%A4%E7%A7%8D%E6%96%B9%E5%BC%8F"><span class="nav-number">3.</span> <span class="nav-text">端口开发的两种方式</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#permanent%E5%8F%82%E6%95%B0%E5%92%8Czone%E5%8F%82%E6%95%B0"><span class="nav-number">4.</span> <span class="nav-text">permanent参数和zone参数</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#firewall-cmd%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4"><span class="nav-number">5.</span> <span class="nav-text">firewall-cmd常用命令</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E6%80%BB%E7%BB%93"><span class="nav-number">6.</span> <span class="nav-text">总结</span></a></li></ol></div>
  162. </div>
  163. <!--/noindex-->
  164. <div class="site-overview-wrap sidebar-panel">
  165. <div class="site-author site-overview-item animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
  166. <img class="site-author-image" itemprop="image" alt="知行"
  167. src="/images/apple-touch-icon.png">
  168. <p class="site-author-name" itemprop="name">知行</p>
  169. <div class="site-description" itemprop="description">韭零后一枚,技术菜鸟,喜欢做白日梦,热爱修仙,任职于一小公司里撸代码。</div>
  170. </div>
  171. <div class="site-state-wrap site-overview-item animated">
  172. <nav class="site-state">
  173. <div class="site-state-item site-state-posts">
  174. <a href="/archives/">
  175. <span class="site-state-item-count">45</span>
  176. <span class="site-state-item-name">日志</span>
  177. </a>
  178. </div>
  179. <div class="site-state-item site-state-categories">
  180. <a href="/categories/">
  181. <span class="site-state-item-count">29</span>
  182. <span class="site-state-item-name">分类</span></a>
  183. </div>
  184. <div class="site-state-item site-state-tags">
  185. <a href="/tags/">
  186. <span class="site-state-item-count">27</span>
  187. <span class="site-state-item-name">标签</span></a>
  188. </div>
  189. </nav>
  190. </div>
  191. <div class="links-of-author site-overview-item animated">
  192. <span class="links-of-author-item">
  193. <a href="https://github.com/izhixing" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;izhixing" rel="noopener" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
  194. </span>
  195. <span class="links-of-author-item">
  196. <a href="mailto:3137650480@qq.com" title="E-Mail → mailto:3137650480@qq.com" rel="noopener" target="_blank"><i class="fa fa-envelope fa-fw"></i>E-Mail</a>
  197. </span>
  198. </div>
  199. </div>
  200. </div>
  201. </div>
  202. </aside>
  203. <div class="sidebar-dimmer"></div>
  204. </header>
  205. <div class="back-to-top" role="button">
  206. <i class="fa fa-arrow-up"></i>
  207. <span>0%</span>
  208. </div>
  209. <a href="https://github.com/izhixing" class="github-corner" title="Follow me on GitHub" aria-label="Follow me on GitHub" rel="noopener" target="_blank"><svg width="80" height="80" viewBox="0 0 250 250" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a>
  210. <noscript>
  211. <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
  212. </noscript>
  213. <div class="main-inner post posts-expand">
  214. <div class="post-block">
  215. <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
  216. <link itemprop="mainEntityOfPage" href="https://blog.izhixing.icu/posts/c62f803c.html">
  217. <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
  218. <meta itemprop="image" content="/images/apple-touch-icon.png">
  219. <meta itemprop="name" content="知行">
  220. <meta itemprop="description" content="韭零后一枚,技术菜鸟,喜欢做白日梦,热爱修仙,任职于一小公司里撸代码。">
  221. </span>
  222. <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
  223. <meta itemprop="name" content="知行">
  224. </span>
  225. <header class="post-header">
  226. <h1 class="post-title" itemprop="name headline">
  227. Linux操作指南:02-配置防火墙端口
  228. </h1>
  229. <div class="post-meta-container">
  230. <div class="post-meta">
  231. <span class="post-meta-item">
  232. <span class="post-meta-item-icon">
  233. <i class="far fa-calendar"></i>
  234. </span>
  235. <span class="post-meta-item-text">发表于</span>
  236. <time title="创建时间:2021-03-27 21:10:14" itemprop="dateCreated datePublished" datetime="2021-03-27T21:10:14+08:00">2021-03-27</time>
  237. </span>
  238. <span class="post-meta-item">
  239. <span class="post-meta-item-icon">
  240. <i class="far fa-calendar-check"></i>
  241. </span>
  242. <span class="post-meta-item-text">更新于</span>
  243. <time title="修改时间:2021-04-06 22:39:44" itemprop="dateModified" datetime="2021-04-06T22:39:44+08:00">2021-04-06</time>
  244. </span>
  245. <span class="post-meta-item">
  246. <span class="post-meta-item-icon">
  247. <i class="far fa-folder"></i>
  248. </span>
  249. <span class="post-meta-item-text">分类于</span>
  250. <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
  251. <a href="/categories/Linux/" itemprop="url" rel="index"><span itemprop="name">Linux</span></a>
  252. </span>
  253. </span>
  254. <span id="/posts/c62f803c.html" class="post-meta-item leancloud_visitors" data-flag-title="Linux操作指南:02-配置防火墙端口" title="阅读次数">
  255. <span class="post-meta-item-icon">
  256. <i class="far fa-eye"></i>
  257. </span>
  258. <span class="post-meta-item-text">阅读次数:</span>
  259. <span class="leancloud-visitors-count"></span>
  260. </span>
  261. </div>
  262. </div>
  263. </header>
  264. <div class="post-body" itemprop="articleBody">
  265. <p>新装的Linux系统,ssh、nginx、tomcat等各种服务都安装好了,可是在外网却访问不了??这十有八九是防火墙的端口没有打开了。</p>
  266. <span id="more"></span>
  267. <h1 id="环境"><a href="#环境" class="headerlink" title="环境"></a>环境</h1><p>系统:CentOS 7</p>
  268. <h1 id="firewall-cmd与iptables"><a href="#firewall-cmd与iptables" class="headerlink" title="firewall-cmd与iptables"></a>firewall-cmd与iptables</h1><p>到了CentOS 7,防火墙的操作命令由<em>iptables</em>改为了<em>firewall-cmd</em>了。以下是摘抄自<a target="_blank" rel="noopener" href="https://wangchujiang.com/linux-command/c/firewall-cmd.html">他人</a>的解释:</p>
  269. <blockquote>
  270. <p>firewall-cmd 是 firewalld的字符界面管理工具,firewalld是centos7的一大特性,最大的好处有两个:支持动态更新,不用重启服务;第二个就是加入了防火墙的“zone”概念。</p>
  271. <p>firewalld跟iptables比起来至少有两大好处:</p>
  272. <ol>
  273. <li>firewalld可以动态修改单条规则,而不需要像iptables那样,在修改了规则后必须得全部刷新才可以生效。</li>
  274. <li>firewalld在使用上要比iptables人性化很多,即使不明白“五张表五条链”而且对TCP/IP协议也不理解也可以实现大部分功能。</li>
  275. </ol>
  276. <p>firewalld自身并不具备防火墙的功能,而是和iptables一样需要通过内核的netfilter来实现,也就是说firewalld和 iptables一样,他们的作用都是用于维护规则,而真正使用规则干活的是内核的netfilter,只不过firewalld和iptables的结 构以及使用方法不一样罢了。</p>
  277. </blockquote>
  278. <p>总的来说这次变更带来的直观好处就是变的更方便更好用了。</p>
  279. <h1 id="端口开发的两种方式"><a href="#端口开发的两种方式" class="headerlink" title="端口开发的两种方式"></a>端口开发的两种方式</h1><p>开放端口有两种方式:指定端口和指定服务。</p>
  280. <p>指定端口很好理解,就是写上那个端口号就开放那个端口。</p>
  281. <p>指定服务可以理解为内置的一个端口映射,默认情况下:ssh服务端口是22、http服务端口是80、MySQL服务端口是3306、tomcat服务端口是8080,因此用服务名来代替直接指定端口,方便记忆和使用。</p>
  282. <p><strong>要注意的是:通过指定服务名开放的就要通过指定服务名关闭;通过指定端口号开放的就要通过指定端口号关闭,且指定端口的时候一定要指定是什么协议,tcp 还是 udp。</strong></p>
  283. <h1 id="permanent参数和zone参数"><a href="#permanent参数和zone参数" class="headerlink" title="permanent参数和zone参数"></a>permanent参数和zone参数</h1><p>配置端口的时候这两个参数是会经常使用到的。</p>
  284. <figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">firewall-cmd --permanent</span><br></pre></td></tr></table></figure>
  285. <p>这个很好理解,就是让配置永久生效的意思。</p>
  286. <figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">firewall-cmd --zone=public</span><br></pre></td></tr></table></figure>
  287. <p><strong>zone</strong>参数就难以理解一点,这个参数的作用是指定一套规则集合,依靠这些规则来判断是否放行数据。这里使用的规则集是<strong>public</strong>,即只放行已配置的服务(端口)。</p>
  288. <p>更详细的可以参考:<a target="_blank" rel="noopener" href="http://www.excelib.com/article/287/show/#g5vTC3">Firewalld的结构</a>,<a target="_blank" rel="noopener" href="https://www.cnblogs.com/excelib/p/5155951.html">用活Firewalld防火墙中的zone</a></p>
  289. <h1 id="firewall-cmd常用命令"><a href="#firewall-cmd常用命令" class="headerlink" title="firewall-cmd常用命令"></a>firewall-cmd常用命令</h1><p>增加端口</p>
  290. <figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash"> 指定端口</span></span><br><span class="line">firewall-cmd --zone=public --add-port=80/tcp --permanent</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span><span class="bash"> 指定服务</span></span><br><span class="line">firewall-cmd --add-service=http --permanent</span><br></pre></td></tr></table></figure>
  291. <p>移除端口</p>
  292. <figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash"> 指定端口</span></span><br><span class="line">firewall-cmd --permanent --remove-port=80/tcp</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span><span class="bash"> 指定服务</span></span><br><span class="line">firewall-cmd --permanent --remove-service=http</span><br></pre></td></tr></table></figure>
  293. <p>显示防火墙运行状态</p>
  294. <figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">firewall-cmd --state</span><br></pre></td></tr></table></figure>
  295. <p>仅显示打开的端口信息</p>
  296. <figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">firewall-cmd --list-ports</span><br></pre></td></tr></table></figure>
  297. <p>仅显示增加的服务信息</p>
  298. <figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">firewall-cmd --list-service</span><br></pre></td></tr></table></figure>
  299. <p>显示所有信息</p>
  300. <figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">firewall-cmd --list-all</span><br></pre></td></tr></table></figure>
  301. <p>配置完之后,必须要重启防火墙让配置生效,如下命令的意思是不中断连接重新加载防火墙配置</p>
  302. <figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">firewall-cmd --reload</span><br></pre></td></tr></table></figure>
  303. <h1 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h1><p>这里只是列举了自己常用的一些命令,更具体的可以参考以下文章</p>
  304. <ul>
  305. <li><p><a target="_blank" rel="noopener" href="https://wangchujiang.com/linux-command/c/firewall-cmd.html">firewall-cmd详解</a></p>
  306. </li>
  307. <li><p><a target="_blank" rel="noopener" href="http://www.excelib.com/article/287/show/#g5vTC3">Firewalld的结构</a></p>
  308. </li>
  309. <li><p><a target="_blank" rel="noopener" href="https://www.cnblogs.com/excelib/p/5155951.html">用活Firewalld防火墙中的zone</a></p>
  310. </li>
  311. </ul>
  312. </div>
  313. <footer class="post-footer">
  314. <div class="post-tags">
  315. <a href="/tags/Linux/" rel="tag"># Linux</a>
  316. </div>
  317. <div class="post-nav">
  318. <div class="post-nav-item">
  319. <a href="/posts/bdb89eee.html" rel="prev" title="Gogs配置为服务开机自启动">
  320. <i class="fa fa-chevron-left"></i> Gogs配置为服务开机自启动
  321. </a>
  322. </div>
  323. <div class="post-nav-item">
  324. <a href="/posts/ef0b8374.html" rel="next" title="Linux配置IPV6地址">
  325. Linux配置IPV6地址 <i class="fa fa-chevron-right"></i>
  326. </a>
  327. </div>
  328. </div>
  329. </footer>
  330. </article>
  331. </div>
  332. <div class="comments gitalk-container"></div>
  333. <script>
  334. window.addEventListener('tabs:register', () => {
  335. let { activeClass } = CONFIG.comments;
  336. if (CONFIG.comments.storage) {
  337. activeClass = localStorage.getItem('comments_active') || activeClass;
  338. }
  339. if (activeClass) {
  340. const activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
  341. if (activeTab) {
  342. activeTab.click();
  343. }
  344. }
  345. });
  346. if (CONFIG.comments.storage) {
  347. window.addEventListener('tabs:click', event => {
  348. if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
  349. const commentClass = event.target.classList[1];
  350. localStorage.setItem('comments_active', commentClass);
  351. });
  352. }
  353. </script>
  354. </div>
  355. </main>
  356. <footer class="footer">
  357. <div class="footer-inner">
  358. <div class="copyright">
  359. &copy; 2018 –
  360. <span itemprop="copyrightYear">2021</span>
  361. <span class="with-love">
  362. <i class="fa fa-heart"></i>
  363. </span>
  364. <span class="author" itemprop="copyrightHolder">知行</span>
  365. </div>
  366. <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.js.org/" class="theme-link" rel="noopener" target="_blank">NexT.Gemini</a> 强力驱动
  367. </div>
  368. </div>
  369. </footer>
  370. <script src="https://cdn.jsdelivr.net/npm/animejs@3.2.1/lib/anime.min.js"></script>
  371. <script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/next-boot.js"></script>
  372. <script src="/js/local-search.js"></script>
  373. <script>
  374. (function() {
  375. function leancloudSelector(url) {
  376. url = encodeURI(url);
  377. return document.getElementById(url).querySelector('.leancloud-visitors-count');
  378. }
  379. function addCount(Counter) {
  380. const visitors = document.querySelector('.leancloud_visitors');
  381. const url = decodeURI(visitors.id);
  382. const title = visitors.dataset.flagTitle;
  383. Counter('get', '/classes/Counter?where=' + encodeURIComponent(JSON.stringify({ url })))
  384. .then(response => response.json())
  385. .then(({ results }) => {
  386. if (results.length > 0) {
  387. const counter = results[0];
  388. leancloudSelector(url).innerText = counter.time + 1;
  389. Counter('put', '/classes/Counter/' + counter.objectId, { time: { '__op': 'Increment', 'amount': 1 } })
  390. .catch(error => {
  391. console.error('Failed to save visitor count', error);
  392. });
  393. } else {
  394. leancloudSelector(url).innerText = 'Counter not initialized! More info at console err msg.';
  395. console.error('ATTENTION! LeanCloud counter has security bug, see how to solve it here: https://github.com/theme-next/hexo-leancloud-counter-security. \n However, you can still use LeanCloud without security, by setting `security` option to `false`.');
  396. }
  397. })
  398. .catch(error => {
  399. console.error('LeanCloud Counter Error', error);
  400. });
  401. }
  402. function showTime(Counter) {
  403. const visitors = document.querySelectorAll('.leancloud_visitors');
  404. const entries = [...visitors].map(element => {
  405. return decodeURI(element.id);
  406. });
  407. Counter('get', '/classes/Counter?where=' + encodeURIComponent(JSON.stringify({ url: { '$in': entries } })))
  408. .then(response => response.json())
  409. .then(({ results }) => {
  410. for (let url of entries) {
  411. const target = results.find(item => item.url === url);
  412. leancloudSelector(url).innerText = target ? target.time : 0;
  413. }
  414. })
  415. .catch(error => {
  416. console.error('LeanCloud Counter Error', error);
  417. });
  418. }
  419. const { app_id, app_key, server_url } = {"enable":true,"app_id":"EVuNVQdwjVVETLVOGGdClySN-gzGzoHsz","app_key":"UBIufuTIEV1gHcdJIx6IOmyN","server_url":null,"security":true};
  420. function fetchData(api_server) {
  421. const Counter = (method, url, data) => {
  422. return fetch(`${api_server}/1.1${url}`, {
  423. method,
  424. headers: {
  425. 'X-LC-Id' : app_id,
  426. 'X-LC-Key' : app_key,
  427. 'Content-Type': 'application/json',
  428. },
  429. body: JSON.stringify(data)
  430. });
  431. };
  432. if (CONFIG.page.isPost) {
  433. if (CONFIG.hostname !== location.hostname) return;
  434. addCount(Counter);
  435. } else if (document.querySelectorAll('.post-title-link').length >= 1) {
  436. showTime(Counter);
  437. }
  438. }
  439. const api_server = app_id.slice(-9) === '-MdYXbMMI' ? `https://${app_id.slice(0, 8).toLowerCase()}.api.lncldglobal.com` : server_url;
  440. if (api_server) {
  441. fetchData(api_server);
  442. } else {
  443. fetch('https://app-router.leancloud.cn/2/route?appId=' + app_id)
  444. .then(response => response.json())
  445. .then(({ api_server }) => {
  446. fetchData('https://' + api_server);
  447. });
  448. }
  449. })();
  450. </script>
  451. <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/gitalk@1.7.0/dist/gitalk.css">
  452. <script>
  453. NexT.utils.loadComments('.gitalk-container', () => {
  454. NexT.utils.getScript('https://cdn.jsdelivr.net/npm/gitalk@1.7.0/dist/gitalk.min.js', () => {
  455. var gitalk = new Gitalk({
  456. clientID : '37644037ac52d12cdd8a',
  457. clientSecret: '09993925bc5a09337e2d13cc1225761ca099d39b',
  458. repo : 'izhixing.github.io',
  459. owner : 'izhixing',
  460. admin : ['izhixing'],
  461. id : '373545c72eaa426e2ef886294ab9a96f',
  462. proxy : 'https://cors-anywhere.herokuapp.com/https://github.com/login/oauth/access_token',
  463. language: '',
  464. distractionFreeMode: true
  465. });
  466. gitalk.render(document.querySelector('.gitalk-container'));
  467. }, window.Gitalk);
  468. });
  469. </script>
  470. </body>
  471. </html>