小昱个人博客
欢迎来到小昱的世界

勤学如春起之苗,不见其增,日有所长;辍学如磨刀之石,不见其损,日有所亏
linux下防火墙的设置
  • 首页 > 运维 > Linux
  • 作者:小昱
  • 2017年6月10日 12:59 星期六
  • 浏览:601
  • 字号:
  • 评论:43
  • 一、Linux防火墙操作

    1.重启后生效

    #开启: 
    chkconfig iptables on 
    #关闭: 
    chkconfig iptables off

    2.即时生效

    #开启: 
    service iptables start 
    #关闭: 
    service iptables stop

    3.配置文件

    vim /etc/sysconfig/iptables

    修改/etc/sysconfig/iptables 文件,添加以下内容:

    -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT 开启80端口访问
    -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT #开启22端口访问
    -A INPUT -m state –state NEW -m tcp -p tcp –dport 443 -j ACCEPT #开启443端口访问
    # 在-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 22 -j ACCEPT前加#号注释掉,即可屏蔽默认的22端口访问

    重启防火墙使得配置文件生效

    /etc/init.d/iptables restart


    但是,在Linux不同的操作系统下,防火墙的设置方法可能不同,如centOS和Ubuntu,具体操作如下:


    二、CentOS7 下防火墙的操作

    CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙步骤。

    1.关闭firewall

    systemctl stop firewalld.service #停止firewall
    systemctl disable firewalld.service #禁止firewall开机启动
    firewall-cmd --state #查看默认防火墙状态(关闭后显示notrunning,开启后显示running)

    2.iptables防火墙(这里iptables已经安装,下面进行配置)

    vi/etc/sysconfig/iptables #编辑防火墙配置文件
    
    # sampleconfiguration for iptables service
    # you can edit thismanually or use system-config-firewall
    # please do not askus to add additional ports/services to this default configuration
    *filter
    :INPUT ACCEPT [0:0]
    :FORWARD ACCEPT[0:0]
    :OUTPUT ACCEPT[0:0]
    -A INPUT -m state--state RELATED,ESTABLISHED -j ACCEPT
    -A INPUT -p icmp -jACCEPT
    -A INPUT -i lo -jACCEPT
    -A INPUT -p tcp -mstate --state NEW -m tcp --dport 22 -j ACCEPT
    -A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -jACCEPT
    -A INPUT -p tcp -m state --state NEW -m tcp --dport 8080-j ACCEPT
    -A INPUT -j REJECT--reject-with icmp-host-prohibited
    -A FORWARD -jREJECT --reject-with icmp-host-prohibited
    COMMIT
    :wq! #保存退出

    备注:这里使用80和8080端口为例。*部分一般添加到“-A INPUT -p tcp -m state —state NEW -m tcp—dport 22 -j ACCEPT”行的上面或者下面,切记不要添加到最后一行,否则防火墙重启后不生效。

    systemctlrestart iptables.service #最后重启防火墙使配置生效
    systemctlenable iptables.service #设置防火墙开机启动

    三、Ubuntu下防火墙的操作

    LInux原始的防火墙工具iptables由于过于繁琐,所以ubuntu系统默认提供了一个基于iptable之上的防火墙工具ufw。而UFW支持图形界面操作,只需在命令行运行ufw命令即能看到一系列的操作。

    1.安装与卸载

    安装

    apt-get install iptables
    apt-get install ufw

    卸载

    apt-get remove iptables
    apt-get remove ufw

    2.开启与关闭

    关闭ubuntu的防火墙 :

    ufw disable

    开启ubuntu的防火墙 :

    ufw enable

    启用ufw

    ufw enable
    ufw default deny

    3.常用操作

    开启和禁用

    ufw allow \|deny [service]

    打开或关闭某个端口

    例如:

    ufw allow smtp #允许所有的外部IP访问本机的25/tcp (smtp)端口
    ufw allow 22/tcp #允许所有的外部IP访问本机的22/tcp (ssh)端口
    ufw allow 53 #允许外部访问53端口(tcp/udp)
    ufw allow from 192.168.1.100 #允许此IP访问所有的本机端口
    ufw allow proto udp 192.168.0.1 port 53 to 192.168.0.2 port 53
    ufw allow from 202.203.0.0 port 22 to 202.203.255.255 port 22
    ufw deny smtp #禁止外部访问smtp服务
    ufw delete allow smtp #删除上面建立的某条规则

    查看防火墙状态

    ufw status

    允许某特定 IP

    ufw allow from xxx.xxx.xx.xxx

    删除 smtp 端口的许可

    ufw delete allow smtp
    ufw delete allow 22
    ufw delete allow allow from 202.203.0.0 port 22 to 202.203.255.255 port 22


    ufw01


    ufw02


    ufw03

      您阅读这篇文章共花了:  
    二维码加载中...
    本文作者:小昱      文章标题: linux下防火墙的设置
    本文地址:http://www.xiaoyulive.top/?post=76
    版权声明:若无注明,本文皆为“小昱个人博客”原创,转载请保留文章出处。
    HectorWah2018-02-11 04:44
    Check out these Max Steel pics! 1/2 Max + 1/2 Steel = 1 Whole Awesome. Watch Live TV В· Disney XD Disney Channel Disney Junior Disable auto-play. Dec 15, 2016: Netflix renewed Haters Back Off for Season 2! Previous Episode. Watch Haters Back Off Season 1 Episode 8 - i'm famous  
    http://watchtvonline.io/season/finding-prince-charming-season-s2-date-recap-watch/ - click to read more
    Does Netflix, Quickflix, Stan, iTunes, etc. stream Game Shakers? Find out where to watch seasons online now! 28 Dec 2016 For TV director John MacCarthy, the series Supernatural is more than just another gig in the province's booming production sector. It's the sole
    JosephMiz2018-01-31 14:56
    <a href="http://omahacomputerrepair.biz/best-admission-essay-editor-website-us">Best admission essay editor website us</a>  help writing a thesis statement  <a href="http://lincolnwebdesignpros.com/best-argumentative-essay-editing-websites-for-mba">Best argumentative essay editing websites for mba</a>  the coursework uk essay depot-book reports  
    <a href=http://lincolnwebdesignpros.com/help-with-my-popular-expository-essay-on-donald-trump>Help with my popular expository essay on donald trump</a>  academic writers required  <a href="http://lincolnwebdesignpros.com/popular-thesis-proposal-ghostwriting-for-hire-uk">Popular thesis proposal ghostwriting for hire uk</a>  creating a cv online essay writers online  
    <a href="http://lincolnwebdesignpros.com/top-dissertation-results-writing-site-gb">Top dissertation results writing site gb</a>  editorial writing examples for uil  <a href="http://lincolnwebdesignpros.com/top-argumentative-essay-writing-websites-sf">Top argumentative essay writing websites sf</a>  buying essays illegal writing a resume template  
    <a href=http://lincolnwebdesignpros.com/esl-letter-writer-websites>Esl letter writer websites</a>  graduate cv writing guide  <a href="http://omahacomputerrepair.biz/professional-papers-writer-sites-toronto">Professional papers writer sites toronto</a>  build a resume website help writing personal statement cv  
    <a href=http://omahacomputerrepair.biz/top-resume-writers-website-gb>Top resume writers website gb</a>  paid writing contests 2013  <a href="http://lincolnwebdesignpros.com/best-home-work-writing-site-for-phd">Best home work writing site for phd</a>  types of essay formats a level maths exam papers  
    <a href="http://omahacomputerrepair.biz/esl-ghostwriting-site-australia">Esl ghostwriting site australia</a>  how do we write a good cv  <a href="http://omahacomputerrepair.biz/professional-admission-paper-editing-sites-sf">Professional admission paper editing sites sf</a>  essay paper sample proposal writer services
    JosephMiz2018-01-30 07:11
    <a href="http://lincolnwebdesignpros.com/esl-home-work-editor-for-hire-online">Esl home work editor for hire online</a>  scholarship essay questions  <a href="http://lincolnwebdesignpros.com/esl-analysis-essay-proofreading-websites-us">Esl analysis essay proofreading websites us</a>  essay on helping the elderly paper writers college  
    <a href=http://lincolnwebdesignpros.com/top-business-plan-writing-sites-sf>Top business plan writing sites sf</a>  essay writing for kids  <a href="http://lincolnwebdesignpros.com/do-my-professional-personal-essay-on-trump">Do my professional personal essay on trump</a>  essay about computer in hindi gcse easter revision courses  
    <a href=http://omahacomputerrepair.biz/blog-writer-for-hire-united-kingdom>Blog writer for hire united kingdom</a>  content writing services  <a href="http://omahacomputerrepair.biz/popular-university-essay-writers-site-toronto">Popular university essay writers site toronto</a>  writing academically online resume maker australia  
    <a href=http://lincolnwebdesignpros.com/masters-essay-writer-sites-united-states>Masters essay writer sites united states</a>  common app essay  <a href=http://lincolnwebdesignpros.com/popular-phd-essay-writing-for-hire-us>Popular phd essay writing for hire us</a>  essay words transition blog writing services india  
    <a href=http://omahacomputerrepair.biz/professional-essay-writers-site-for-mba>Professional essay writers site for mba</a>  writing and essay outline  <a href="http://omahacomputerrepair.biz/esl-essay-writers-for-hire-united-kingdom">Esl essay writers for hire united kingdom</a>  english essay good professional writing online james porter  
    <a href=http://lincolnwebdesignpros.com/esl-university-essay-writing-for-hire-us>Esl university essay writing for hire us</a>  igcse residential revision courses  <a href=http://omahacomputerrepair.biz/write-me-journalism-dissertation-results>Write me journalism dissertation results</a>  online writing help for elementary students secondary education in england
    payday loans2018-01-28 21:36
    debt relief solutions  <a href="https://payday365day.org">secured bad credit loans</a>  loans nashville tn  <a href=https://payday365day.org>fastcash</a>  quick loans nyc  
    cheap installment loans  <a href="https://payday365day.org">small loan calculator</a>  personal loans in usa  <a href=https://payday365day.org>payday loans in st louis mo</a>  loans murfreesboro tn  
    loans with no interest  <a href="https://payday365day.org">bad credit cash loans online</a>  one hour loan reviews  <a href=https://payday365day.org>payday now loans</a>  can you get a loan with no credit  
    islamic loan  <a href="https://payday365day.org">long term payday loan</a>  low interest personal loans bad credit  <a href=https://payday365day.org>loans for bad credit rating</a>  consumer loan rates
    HectorWah2018-01-16 20:27
    Soundtrack from the TV show Greenleaf (Season 1). Listen to the Complete List of Songs; with Scene Descriptions, Music Samples. 2 Mar 2016 FX announced back in October that it had ordered a pilot for an X-Men universe drama called Legion, which would follow the struggles of  
    http://watchtvonline.io/episode/gruen-episode-s1-e7-date-cast-premiere/ - why not find out more
    'Inside Amy Schumer's' Big Return | NBC New York    19 Apr 2016 The fourth season of the comedian's TV show arrives Thursday amid outsized expectations – and she knows it. 5 days ago TV tonight: 'Superstore' finale, 'Amazing Race' Superstore - Season 2 This NBC comedy ends its second season with a disaster on the
    payday loans2018-01-13 21:12
    personal loan with no credit history  <a href="https://payday365day.org">cash express loans</a>  1500 installment loan  <a href=https://payday365day.org>payday loans fresno ca</a>  loan application form  
    instant installment loans  <a href="https://payday365day.org">personal loan for 10000 salary</a>  how to qualify for a loan  <a href=https://payday365day.org>24 hour loans online</a>  no questions asked loans  
    monthly installment loans online  <a href="https://payday365day.org">cash advance interest rate</a>  need a loan bad credit  <a href=https://payday365day.org>payday loans florida</a>  credit builder loan  
    loans without cosigners  <a href="https://payday365day.org">pay check advance</a>  loans for bad credit in california  <a href=https://payday365day.org>personal loans with poor credit</a>  reputable debt consolidation companies
    payday loans2018-01-13 13:44
    small installment loans for bad credit  <a href="https://payday365day.org">bad credit loans direct lenders no fees</a>  what is debt consolidation loan  <a href=https://payday365day.org>microloan program</a>  personal loan banks  
    internet loan  <a href="https://payday365day.org">urgent money</a>  installment lenders  <a href=https://payday365day.org>money lenders online</a>  can i get a personal loan with bad credit  
    best installment loans online  <a href="https://payday365day.org">good loans for bad credit</a>  taking out loans  <a href=https://payday365day.org>bad credit loans maryland</a>  banks personal loans  
    get loan  <a href="https://payday365day.org">payday loans for bad credit direct lenders</a>  loan lenders for people with bad credit  <a href=https://payday365day.org>ez cash</a>  fast loans today
    payday loans2018-01-10 08:09
    low interest debt consolidation loans  <a href="https://payday365day.org">loans in pa</a>  financial loans  <a href=https://payday365day.org>checking account loans</a>  cash loans las vegas  
    installment loans lenders  <a href="https://payday365day.org">fast loan</a>  how hard is it to get a personal loan  <a href=https://payday365day.org>delaware payday loans</a>  personal loans with bad credit and no cosigner  
    loans knoxville tn  <a href="https://payday365day.org">loan companies for people with bad credit</a>  cash loans usa  <a href=https://payday365day.org>cash loan online</a>  debt consolidation az  
    direct loan servicing  <a href="https://payday365day.org">payday loans for bad credit online</a>  best personal loans for bad credit  <a href=https://payday365day.org>online cash loans same day</a>  loans for debt consolidation
    payday loans2018-01-10 01:21
    installment credit definition  <a href="https://payday365day.org">online cash</a>  what is debt consolidation loan  <a href=https://payday365day.org>easy fast cash loans</a>  current interest rates on personal loans  
    i have bad credit and i need a loan  <a href="https://payday365day.org">how does payday loans work</a>  loans based on income  <a href=https://payday365day.org>online cash register</a>  debt consolidation reviews  
    usa loans  <a href="https://payday365day.org">pay advance loans online</a>  loans with bad credit in ga  <a href=https://payday365day.org>cash loan fast</a>  tribal loans online  
    loan with bad credit score  <a href="https://payday365day.org">american loan services</a>  loan based on income  <a href=https://payday365day.org>need a payday loan today</a>  bank personal loan
    payday loans2018-01-09 17:36
    loans monroe la  <a href="https://payday365day.org">immediate cash</a>  best installment loans online  <a href=https://payday365day.org>direct lenders payday loans online</a>  low fico score personal loans  
    easy quick loans  <a href="https://payday365day.org">find private lenders now</a>  2000 personal loan  <a href=https://payday365day.org>2000 loan with bad credit</a>  long term personal loans  
    unsecured debt consolidation loan  <a href="https://payday365day.org">cash in advance</a>  fair credit personal loans  <a href=https://payday365day.org>advance cash america</a>  loans for people with no income  
    loans jacksonville fl  <a href="https://payday365day.org">payday loans denver co</a>  loans based on income  <a href=https://payday365day.org>fast payday</a>  $500 personal loan
    返回顶部| 首页| 碰碰手气| 捐赠支持| 手机版本|后花园

    Copyright © 2016-2017 小昱个人博客 滇ICP备16006294号