电脑知识|欧美黑人一区二区三区|软件|欧美黑人一级爽快片淫片高清|系统|欧美黑人狂野猛交老妇|数据库|服务器|编程开发|网络运营|知识问答|技术教程文章 - 好吧啦网

您的位置:首頁技術文章
文章詳情頁

FreeBSD配置防火墻開啟SSH服務的方法

瀏覽:270日期:2022-06-03 16:51:41
1、配置FreeBSD 防火墻
ee /etc/rc.conf   #編輯,在最后添加
firewall_enable="yes"  #開啟防火墻
net.inet.ip.fw.verbose=1   #啟用防火墻日志功能
net.inet.ip.fw.verbose_limit=5  #啟用防火墻日志功能
natd_enable="YES"  # 開啟防火墻NAT功能
natd_interface="rl0"     
natd_flags="-dynamic -m"
firewall_script="/etc/ipfw.rules"      #自定義防火墻規則路徑
按esc,回車,再按a保存配置
2、添加防火墻規則

ee /etc/ipfw.rules    #編輯防火墻規則,添加以下代碼
#!/bin/sh
################ Start of IPFW rules file ######################
# Flush out the list before we begin.
ipfw -q -f flush

# Set rules command prefix
cmd="ipfw -q add"
skip="skipto 800"
pif="rl0"     # public interface name of NIC
              # facing the public Internet

#################################################################
# No restrictions on Inside LAN Interface for private network
# Change xl0 to your LAN NIC interface name
#################################################################
$cmd 005 allow all from any to any via xl0

#################################################################
# No restrictions on Loopback Interface
#################################################################
$cmd 010 allow all from any to any via lo0

#################################################################
# check if packet is inbound and nat address if it is
#################################################################
$cmd 014 divert natd ip from any to any in via $pif

#################################################################
# Allow the packet through if it has previous been added to the
# the "dynamic" rules table by a allow keep-state statement.
#################################################################
$cmd 015 check-state

#################################################################
# Interface facing Public Internet (Outbound Section)
# Check session start requests originating from behind the
# firewall on the private network or from this gateway server
# destined for the public Internet.
#################################################################

# Allow out access to my ISP"s Domain name server.
# x.x.x.x must be the IP address of your ISP"s DNS
# Dup these lines if your ISP has more than one DNS server
# Get the IP addresses from /etc/resolv.conf file
$cmd 020 $skip tcp from any to x.x.x.x 53 out via $pif setup keep-state
# Allow out access to my ISP"s DHCP server for cable/DSL configurations.
$cmd 030 $skip udp from any to x.x.x.x 67 out via $pif keep-state

# Allow out non-secure standard www function
$cmd 040 $skip tcp from any to any 80 out via $pif setup keep-state

# Allow out secure www function https over TLS SSL
$cmd 050 $skip tcp from any to any 443 out via $pif setup keep-state

# Allow out send & get email function
$cmd 060 $skip tcp from any to any 25 out via $pif setup keep-state
$cmd 061 $skip tcp from any to any 110 out via $pif setup keep-state

# Allow out FreeBSD (make install & CVSUP) functions
# Basically give user root "GOD" privileges.
$cmd 070 $skip tcp from me to any out via $pif setup keep-state uid root

# Allow out ping
$cmd 080 $skip icmp from any to any out via $pif keep-state

# Allow out Time
$cmd 090 $skip tcp from any to any 37 out via $pif setup keep-state

# Allow out nntp news (i.e. news groups)
$cmd 100 $skip tcp from any to any 119 out via $pif setup keep-state

# Allow out secure FTP, Telnet, and SCP
# This function is using SSH (secure shell)
$cmd 110 $skip tcp from any to any 22 out via $pif setup keep-state

# Allow out whois
$cmd 120 $skip tcp from any to any 43 out via $pif setup keep-state

# Allow ntp time server
$cmd 130 $skip udp from any to any 123 out via $pif keep-state

#################################################################
# Interface facing Public Internet (Inbound Section)
# Check packets originating from the public Internet
# destined for this gateway server or the private network.
#################################################################

# Deny all inbound traffic from non-routable reserved address spaces
#$cmd 300 deny all from 192.168.0.0/16  to any in via $pif  #RFC 1918 private IP
$cmd 301 deny all from 172.16.0.0/12   to any in via $pif  #RFC 1918 private IP
$cmd 302 deny all from 10.0.0.0/8      to any in via $pif  #RFC 1918 private IP
$cmd 303 deny all from 127.0.0.0/8     to any in via $pif  #loopback
$cmd 304 deny all from 0.0.0.0/8       to any in via $pif  #loopback
$cmd 305 deny all from 169.254.0.0/16  to any in via $pif  #DHCP auto-config
$cmd 306 deny all from 192.0.2.0/24    to any in via $pif  #reserved for docs
$cmd 307 deny all from 204.152.64.0/23 to any in via $pif  #Sun cluster
$cmd 308 deny all from 224.0.0.0/3     to any in via $pif  #Class D & E multicast

# Deny ident
$cmd 315 deny tcp from any to any 113 in via $pif

# Deny all Netbios service. 137=name, 138=datagram, 139=session
# Netbios is MS/Windows sharing services.
# Block MS/Windows hosts2 name server requests 81
$cmd 320 deny tcp from any to any 137 in via $pif
$cmd 321 deny tcp from any to any 138 in via $pif
$cmd 322 deny tcp from any to any 139 in via $pif
$cmd 323 deny tcp from any to any 81  in via $pif

# Deny any late arriving packets
$cmd 330 deny all from any to any frag in via $pif

# Deny ACK packets that did not match the dynamic rule table
$cmd 332 deny tcp from any to any established in via $pif

# Allow traffic in from ISP"s DHCP server. This rule must contain
# the IP address of your ISP"s DHCP server as it"s the only
# authorized source to send this packet type.
# Only necessary for cable or DSL configurations.
# This rule is not needed for "user ppp" type connection to
# the public Internet. This is the same IP address you captured
# and used in the outbound section.
$cmd 360 allow udp from x.x.x.x to any 68 in via $pif keep-state

# Allow in standard www function because I have Apache server
$cmd 370 allow tcp from any to me 80 in via $pif setup limit src-addr 2

# Allow in secure FTP, Telnet, and SCP from public Internet
$cmd 380 allow tcp from any to me 22 in via $pif setup limit src-addr 2

# Allow in non-secure Telnet session from public Internet
# labeled non-secure because ID & PW are passed over public
# Internet as clear text.
# Delete this sample group if you do not have telnet server enabled.
$cmd 390 allow tcp from any to me 23 in via $pif setup limit src-addr 2

# Reject & Log all unauthorized incoming connections from the public Internet
$cmd 400 deny log all from any to any in via $pif

# Reject & Log all unauthorized out going connections to the public Internet
$cmd 450 deny log all from any to any out via $pif

# This is skipto location for outbound stateful rules
$cmd 800 divert natd ip from any to any out via $pif
$cmd 801 allow ip from any to any

# Everything else is denied by default
# deny and log all packets that fell through to see what they are
$cmd 999 deny log all from any to any
################ End of IPFW rules file ###############################

  

備注:參數說明:
#$cmd 300 deny all from 192.168.0.0/16  to any in via $pif  #RFC 1918 private IP
我的IP地址是192.168.21.173,是屬于192.168.0.0/16 IP段,所以這里要注釋掉這一行,允許連接外網,否則主機無法聯網。
$cmd 380 allow tcp from any to me 22 in via $pif setup limit src-addr 2
是開啟SSH默認端口22
3、重啟網絡服務,使防火墻規則生效

/etc/netstart  #重啟網絡
/etc/rc.d/ipfw start     #開啟防火墻
ipfw disable firewall    #關閉防火墻
ipfw enable firewall   #開啟防火墻
/etc/rc.d/ipfw  restart   #重啟防火墻
sh /etc/ipfw.rules     #使防火墻規則生效
4、開啟SSH服務
(1)ee  /etc/inetd.conf  #編輯,去掉sshd前面的#
ssh     stream  tcp     nowait  root    /usr/sbin/sshd          sshd -i -4
(2)ee  /etc/rc.conf   #編輯,在最后添加
sshd_enable="yes"  
(3)ee  /etc/ssh/sshd_config  #編輯配置文件
PermitRootLogin yes   #允許root登錄
PasswordAuthentication yes    #使用密碼驗證
PermitEmptyPasswords no   #不允許空密碼登錄
/etc/rc.d/sshd start  #啟動ssh服務
/etc/rc.d/sshd restart    #重啟ssh
配置完成,現在已經可以使用Putty等遠程連接工具連接服務器了。
#####################################################
擴展閱讀:

有兩種加載自定義 ipfw 防火墻規則的方法。
其一是將變量 firewall_type 設為包含不帶 ipfw(8) 命令行選項的 防火墻規則 文件的完整路徑。
例如:
add allow in
add allow out
firewall_type="open"參數說明
open ── 允許所有流量通過。
client ── 只保護本機。
simple ── 保護整個網絡。
closed ── 完全禁止除回環設備之外的全部 IP 流量。
UNKNOWN ── 禁止加載防火墻規則。
filename ── 到防火墻規則文件的絕對路徑。
IPFW防火墻規則集樣例在這兩個文件中
/etc/rc.firewall
/etc/rc.firewall6
除此之外, 也可以將 firewall_script 變量設為包含 ipfw 命令的可執行腳本, 這樣這個腳本會在啟動時自動執行。
#####################################################

相關文章:
主站蜘蛛池模板: 苏州注册公司_苏州代理记账_苏州工商注册_苏州代办公司-恒佳财税 | 福兰德PVC地板|PVC塑胶地板|PVC运动地板|PVC商用地板-中国弹性地板系统专业解决方案领先供应商! 福建成考网-福建成人高考网 | 管家婆-管家婆软件-管家婆辉煌-管家婆进销存-管家婆工贸ERP | 欧美日韩国产一区二区三区不_久久久久国产精品无码不卡_亚洲欧洲美洲无码精品AV_精品一区美女视频_日韩黄色性爱一级视频_日本五十路人妻斩_国产99视频免费精品是看4_亚洲中文字幕无码一二三四区_国产小萍萍挤奶喷奶水_亚洲另类精品无码在线一区 | 浙江浩盛阀门有限公司| 全自动不干胶贴标机_套标机-上海今昂贴标机生产厂家 | 长江船运_国内海运_内贸船运_大件海运|运输_船舶运输价格_钢材船运_内河运输_风电甲板船_游艇运输_航运货代电话_上海交航船运 | 脱硝喷枪-氨水喷枪-尿素喷枪-河北思凯淋环保科技有限公司 | 百方网-百方电气网,电工电气行业专业的B2B电子商务平台 | 高压微雾加湿器_工业加湿器_温室喷雾-昌润空气净化设备 | 奶茶加盟,奶茶加盟店连锁品牌-甜啦啦官网 | 生物风-销售载体,基因,质粒,ATCC细胞,ATCC菌株等,欢迎购买-百风生物 | 扬尘在线监测系统_工地噪声扬尘检测仪_扬尘监测系统_贝塔射线扬尘监测设备「风途物联网科技」 | 色油机-色母机-失重|称重式混料机-称重机-米重机-拌料机-[东莞同锐机械]精密计量科技制造商 | 铝单板_铝窗花_铝单板厂家_氟碳包柱铝单板批发价格-佛山科阳金属 | 接地电阻测试仪[厂家直销]_电缆故障测试仪[精准定位]_耐压测试仪-武汉南电至诚电力设备 | 照相馆预约系统,微信公众号摄影门店系统,影楼管理软件-盟百网络 | 薪动-人力资源公司-灵活用工薪资代发-费用结算-残保金优化-北京秒付科技有限公司 | 首页-恒温恒湿试验箱_恒温恒湿箱_高低温试验箱_高低温交变湿热试验箱_苏州正合 | 皮带机_移动皮带机_大倾角皮带机_皮带机厂家 - 新乡市国盛机械设备有限公司 | 市政路灯_厂家-淄博信达电力科技有限公司| 兰州UPS电源,兰州山特UPS-兰州万胜商贸 | 恒压供水控制柜|无负压|一体化泵站控制柜|PLC远程调试|MCGS触摸屏|自动控制方案-联致自控设备 | 尚为传动-专业高精密蜗轮蜗杆,双导程蜗轮蜗杆,蜗轮蜗杆减速机,蜗杆减速机生产厂家 | 3dmax渲染-效果图渲染-影视动画渲染-北京快渲科技有限公司 | 标准光源箱|对色灯箱|色差仪|光泽度仪|涂层测厚仪_HRC大品牌生产厂家 | 石家庄网站建设|石家庄网站制作|石家庄小程序开发|石家庄微信开发|网站建设公司|网站制作公司|微信小程序开发|手机APP开发|软件开发 | 铁素体测量仪/检测仪/铁素体含量测试仪-苏州圣光仪器有限公司 | 岩棉切条机厂家_玻璃棉裁条机_水泥基保温板设备-廊坊鹏恒机械 | 广东教师资格网-广东教师资格证考试网| 铝箔-铝板-花纹铝板-铝型材-铝棒管-上海百亚金属材料有限公司 | 土壤检测仪器_行星式球磨仪_土壤团粒分析仪厂家_山东莱恩德智能科技有限公司 | 天津货架厂_穿梭车货架_重型仓储货架_阁楼货架定制-天津钢力仓储货架生产厂家_天津钢力智能仓储装备 | 低合金板|安阳低合金板|河南低合金板|高强度板|桥梁板_安阳润兴 北京租车牌|京牌指标租赁|小客车指标出租 | 硅胶制品-硅橡胶制品-东莞硅胶制品厂家-广东帝博科技有限公司 | 上海冠顶工业设备有限公司-隧道炉,烘箱,UV固化机,涂装设备,高温炉,工业机器人生产厂家 | 重庆波纹管|重庆钢带管|重庆塑钢管|重庆联进管道有限公司 | 石牌坊价格石牌坊雕刻制作_石雕牌坊牌楼石栏杆厂家_山东嘉祥石雕有限公司 | 广东燎了网络科技有限公司官网-网站建设-珠海网络推广-高端营销型外贸网站建设-珠海专业h5建站公司「了了网」 | 高清视频编码器,4K音视频编解码器,直播编码器,流媒体服务器,深圳海威视讯技术有限公司 | 武汉刮刮奖_刮刮卡印刷厂_为企业提供门票印刷_武汉合格证印刷_现金劵代金券印刷制作 - 武汉泽雅印刷有限公司 |