Linux下iptables 禁止端口和开放端口

下面的代码如果出现权限问题,就在代码的最前面加上 sudo 赋予权限就可以解决了。

 

一。端口的开启。

     iptables -A INPUT -p tcp --dport 80 -j ACCEPT

     iptables -A OUTPUT -p tcp --sport 80 -j ACCEPT

     -A:参数就看成是添加一条 INPUT(OUTPUT) 的规则;
     -p:指定是什么协议 我们常用的tcp(udp)协议。 例如:53端口的DNS到时我们要配置DNS用到53端口,大家就会发现使用udp协议的;

    --dport:就是目标端口,当数据从外部进入服务器为目标端口;
    --sport:数据从服务器出去 则为数据源端口;

   -j 就是指定是 ACCEPT 接收 或者 DROP 不接收。

 上面这两行代码是开启 80 端口。

 

二。端口的关闭。

     iptables -A INPUT -p tcp --dport 80 -j DROP

     iptables -A OUTPUT -p tcp --sport 80 -j DROP

这样就关闭了 80 端口。

 

三。查看端口命令。

    iptables -L -n    用来查看 iptables 规则。也就是开启的端口等。

 

四。删除 iptables 规则。

   iptables -L -n --line-numbers   查看规则 前面加上序号。

   iptables -D INPUT [ 序号]  通过上面查看得到的序号,通过序号进行删除 iptables 规则。

 

五。规则的保存。

     配置完成后是需要保存的。这时就需要 root 权限。sudo 权限已经不够了。设置好后。输入代码:

     iptables-save > /etc/iptables-rules

     ip6tables-save > /etc/ip6tables-rules

 

    我们需要编辑 /etc/network/interfaces 文件,在最后插入下面两行:

    pre-up iptables-restore < /etc/iptables-rules

    pre-up ip6tables-restore < /etc/ip6tables-rules

 

重启电脑后。使用   sudo iptables -L     查看配置是否生效。

 

六。说明:一般的电脑都安装了 iptables(防火墙)。所以就可以通过上面的方法进行端口的开放。如果没有安装防火墙的电脑,就不需要开启端口。因为没有安装 iptables 的电脑。端口是可以直接访问的。

uniapp [全端兼容] - 实现接入集成高德地图搜索地址及选择位置功能,搜索框检索选择地点并返回经纬度及详细省市区县街道地址,用户搜索历史及清空历史记录,选择地址自动获取周边位置列表/地图移动选点 uni-app,高德地图,h5移动端网页,微信小程序,支付宝小程序,Android安卓,苹果ios,app,nvue,Uniapp高德地图,在地图上选择或搜索指定地点,打开地图选择位置,关联地址搜索,输入地址返回附近地址列表,uniApp高德地图地址搜索,搜索框历史记录,关键字搜索,周边查询,搜索位置,uniapp对接高德实现搜索出现地址以及保存搜索记录,集成高德地图,实现精准位置选点功能,获取当前定位城市,如何实现搜索功能,获取省份城市区街道详细地址经纬度,移动选点标记位置,在地图上进行选择位置选点、搜索 阅读详情

相关推荐

谈谈SAP顾问的几个发展趋势

大家新年好,今天想聊一下对SAP顾问发展趋势的一些个人见解。过去10多年得益于我国的经济发展,外资不断加大在中国的投资和中国企业的发展,SAP顾问行业得到了很大的发展和壮大。那么未来几年SAP顾问的职业发展到底怎么样呢?

syounger的专栏 2515

linux 防火墙的配置

Linux 的防火墙是一个非常重要的安全功能,可以保护系统免受网络攻击。在 Linux 中,有很多种防火墙软件可供选择,其中最常见的是 iptables 和 firewalld。 下面是针对 iptables 的配置步骤: 启用 iptables:在终端中输入 "systemctl start iptables" 命令,使 iptables 启动。 配置规则:输入以下命令来设置防火墙规则: iptables -A INPUT -p tcp --dport 22 -j ACCEPT iptables

dxhklck的博客 1493

保姆级教程:用Multisim仿真快速上手二极管、MOSFET和IGBT的开关特性

本文提供了一份详细的Multisim仿真教程,帮助读者快速掌握二极管、MOSFET和IGBT的开关特性。通过搭建实验电路、观察波形特征和参数影响分析,深入解析了反向恢复过程、米勒平台现象和拖尾电流效应。适合电力电子初学者和工程师通过仿真建立直观理解,提升电路设计能力。

weixin_29290863的博客 499

iptables 防火墙进出控制

iptables 是集成在 Linux 内核中的包过滤防火墙系统。使用 iptables 可以添加、删除具体的过滤规则,iptables 默认维护着 4 个表和 5 个链,所有的防火墙策略规则都被分别写入这些表与链中。“五链”是指内核中控制网络的 NetFilter 定义的 5 个规则链。

不爱吃奶昔(zsl0)的博客 1802

视觉SLAM十四讲--第13讲 实践:设计SLAM系统(最详细的代码调试运行步骤)

最详细的代码调试运行避坑说明,也包含了我自己对代码的理解,如有理解错误的地方,欢迎指正交流。

记录和分享 1万+

英语语法-句法

摘要:本文系统梳理了英语句法知识,重点解析了五种基本句型及其扩展结构。内容包括句子类型(陈述句、疑问句、祈使句、感叹句)、复合句构成(从句分类与连词使用)、特殊句型(倒装、强调、引语转换)等。特别强调句子成分分析技巧,指出每种句子成分可由不同词法单元充当,需掌握成分识别与划分方法。文章还提供了往期语法系列链接,形成完整的英语语法学习体系,帮助读者建立从词法到句法的系统认知框架。

STCNXPARM的博客 8825

iptables禁止访问1端口和80端口

iptables -A INPUT -p tcp --dport 1 -j DROP iptables -A INPUT -p tcp --dport 80 -j DROP 这是在 Linux 系统上使用 iptables 禁止访问 1 端口和 80 端口的命令。其中 -A INPUT 表示添加规则到 INPUT 链,-p tcp 表示使用 TCP 协议,--dport 表示目标端口,-j DRO...

weixin_35751194的博客 2327

Proteus仿真——电压比较器

电压比较器是一种对输入信号进行鉴别与比较的电路,是组成非正弦波发生电路的基本单元电路。常用电压比较器有如下几种:单限比较器、滞回比较器、窗口比较器、集成电压比较器等。

weixin_58745307的博客 3377

利用iptables来配置linux禁止所有端口登陆和开放指定端口

1、关闭所有的 INPUT FORWARD OUTPUT 只对某些端口开放。 下面是命令实现: iptables -P INPUT DROP iptables -P FORWARD DROP iptables -P OUTPUT DROP 再用命令 iptables -L -n 查看 是否设置好, 好看到全部 DROP 了 这样的设置好了,我们只是临时的, 重...

weixin_33727510的博客 4152

深度解析中国支付清算体系

说起国之重器,不仅仅有 东风快递、渔16、渔17、渔18,还有另外一个国之重器-CNAPS2(中国支付清算体系)。 中国国内支付行业的发达水平、繁荣程度,不客气的讲,在全世界都是数一数二的,世界上最大的银行卡组织银联在中国,世界上交易量最大的网络零售支付清算体网联在中国。可以说现在我国经济的高速发展,离不开CNAPS2。

银行信息系统应用架构详解 2517

【tips】在PyCharm中安装opencv图文版详细教程

pip如下图所示,左边的蓝色图标就是终端。点开终端后,键入命令,按下回车后就开始下载了。如果你更喜欢图形化操作,可以在 PyCharm 中直接安装:。点击右上角的 +按钮(添加包)。搜索或,点击。

zhousanguhe的博客 6744

iptables封禁端口

iptables封禁固定端口

solocao的专栏 6059

Python实现PDB文件预处理

蛋白质结构研究依赖PDB文件存储的三维结构数据,但原始文件常含无关的水分子、离子和非标准残基等干扰信息。本文介绍了一个基于BioPython的Python预处理脚本,可自动清理PDB文件,主要功能包括:1)移除短于阈值的蛋白质链;2)过滤非标准氨基酸;3)可选保留水分子和金属离子。该脚本逻辑清晰,支持批量处理,能显著提升结构比对、分子对接等分析前的数据准备效率,为后续生物信息学研究提供更纯净的结构数据基础。

Protein Designer的博客 568

linux iptables禁止端口,Linux下iptables 禁止端口和开放端口示例

1、关闭所有的 INPUT FORWARD OUTPUT 只对某些端口开放。下面是命令实现:iptables -P INPUT DROP iptables -P FORWARD DROP iptables -P OUTPUT DROP再用命令iptables -L -n查看 是否设置好, 好看到全部 DROP 了这样的设置好了,我们只是临时的, 重启服务器还是会恢复原来没有设置的状态还要使用 ...

weixin_29284657的博客 5854

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

centos 利用iptables来配置linux禁止所有端口登陆和开放指定端口的方法

1、关闭所有的 INPUT FORWARD OUTPUT 只对某些端口开放。 下面是命令实现: iptables -P INPUT DROP iptables -P FORWARD DROP iptables -P OUTPUT DROP 再用命令 iptables -L -n 查看 是否设置好, 好看到全部 DROP 了 这样的设置好了,我们只是临时的, 重启服务器还是会恢复原来没有设置的状态 还要使用 service iptables save 进行保存 看到信息 firewall rule

2641

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

判断端口是否能用_用iptables来配置linux,禁止所有端口登陆和开放指定端口的方法...

明晨随风 2019-11-30 10:25:211、关闭所有的 INPUT FORWARD OUTPUT 只对某些端口开放。下面是命令实现:iptables -P INPUT DROPiptables -P FORWARD DROPiptables -P OUTPUT DROP再用命令 iptables -L -n 查看 是否设置好, 好看到全部 DROP 了这样的设置好了,我们只是临时的, 重启...

weixin_39844481的博客 300

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

iptables禁用mysql端口_Linux下iptables 禁止端口和开放端口

1、关闭所有的 INPUT FORWARD OUTPUT 只对某些端口开放。下面是命令实现:iptables -P INPUT DROPiptables -P FORWARD DROPiptables -P OUTPUT DROP再用命令iptables -L -n查看 是否设置好, 好看到全部 DROP 了这样的设置好了,我们只是临时的, 重启服务器还是会恢复原来没有设置的状态还要使用 serv...

weixin_36432451的博客 218
上一篇: linux DNS修改
下一篇: mongodb远程链接配置
黄祚敏
博客等级 码龄10年 22粉丝 89原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值