Telnet tftp cvs 等IP限制在CentOS 7 Systemd的使用

2024-02-04 10:38

本文主要是介绍Telnet tftp cvs 等IP限制在CentOS 7 Systemd的使用,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

单片机还是需要telnet和tftp的。家里的这台服务器也提供外网接口开放,这两个服务不方便对外开放。以前telnet用xinet绑定指定网卡和限制IP访问。CentOS开始使用systemd作为telnet启动,规矩和以前不一样了。记录一下

原理:

          Service units acquired two new options IPAddressAllow= andIPAddressDeny=, taking a list of IPv4 or IPv6 addresses and masks,for configuring a simple IP access control list for all sockets ofthe unit. These options are available also on .slice and .socketunits, permitting flexible access list configuration for individualservices as well as groups of services (as defined by a slice unit),including system-wide. Note that IP ACLs configured this way areenforced on every single IPv4 and IPv6 socket created by any processof the service unit, and apply to ingress as well as egress traffic.

添加service unit增加两个选项:IPAddressAllow / IPAddressDeny,和 socket 里增加 BindToDeivce命令。

telnet修改,限制 IP/网卡

[root@sh ~]# cat /usr/lib/systemd/system/telnet@.service
[Unit]
Description=Telnet Server
After=local-fs.target[Service]
#Modified,Modified,Modified
IPAddressAllow=192.168.0.0/24ExecStart=-/usr/sbin/in.telnetd
StandardInput=socket[root@sh ~]# cat /usr/lib/systemd/system/telnet.socket 
[Unit]
Description=Telnet Server Activation Socket
Documentation=man:telnetd(8)[Socket]
#Modified,Modified,Modified
BindToDevice=enp3s0ListenStream=23
Accept=true[Install]
WantedBy=sockets.target
[root@sh ~]# 

tftp  的修改,限制 IP/网卡

[root@sh ~]# cat /usr/lib/systemd/system/tftp.socket 
[Unit]
Description=Tftp Server Activation Socket[Socket]
#Modified,Modified,Modified
BindToDevice=enp3s0
ListenDatagram=69[Install]
WantedBy=sockets.target[root@sh ~]# cat /usr/lib/systemd/system/tftp.service 
[Unit]
Description=Tftp Server
Requires=tftp.socket
Documentation=man:in.tftpd[Service]
ExecStart=/usr/sbin/in.tftpd -s /var/lib/tftpboot
StandardInput=socket#Modified,Modified,Modified
IPAddressAllow=192.168.0.0/24[Install]
Also=tftp.socket
[root@sh ~]# 

分别在Socket文件的 [Socket] 段落增加了
BindToDevice=enp3s0 (内网设备名)
或 #ListenStream=192.168.0.2:2401 

在service文件的 [Service] 段落增加了
IPAddressAllow=192.168.0.0/24

两个限制。

CVS 限制 IP/网卡

[root@localhost ~]# cat /usr/lib/systemd/system/cvs.socket
[Unit]
Description=CVS Server Activation Socket
PartOf=cvs.target[Socket]
#允许外网 
ListenStream=2401#仅允许内网
#ListenStream=192.168.0.2:2401
Accept=true[Install]
WantedBy=sockets.target[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]#cat /usr/lib/systemd/system/cvs.target
[Unit]
Description=CVS Servers[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]#cat /usr/lib/systemd/system/cvs@.service
[Unit]
Description=CVS Server
After=local-fs.target
PartOf=cvs.target[Service]
Environment=HOME=/var/cvs
ExecStart=-/usr/bin/cvs -f --allow-root=/var/cvs pserver
StandardInput=socket

CVS有时需要在外网使用,如果是内网:

#仅允许内网
#ListenStream=192.168.0.2:2401

 vsftp,standalone 模式运行

listen=YES
#
# This directive enables listening on IPv6 sockets. By default, listening
# on the IPv6 "any" address (::) will accept connections from both IPv6
# and IPv4 clients. It is not necessary to listen on *both* IPv4 and IPv6
# sockets. If you want that (perhaps because you want to listen on specific
# addresses) then you must run two copies of vsftpd with two configuration
# files.
# Make sure, that one of the listen options is commented !!
listen_ipv6=NO

listen=YES,开启standalone模式;

listen_ipv6关闭,否则启动不起来。

参考:关于vsftp启动报错的解决办法_唯独你的好的博客-CSDN博客

DHCP,限制IP

[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]#cat /usr/lib/systemd/system/dhcpd.service
[Unit]
Description=DHCPv4 Server Daemon
Documentation=man:dhcpd(8) man:dhcpd.conf(5)
Wants=network-online.target
After=network-online.target
After=time-sync.target[Service]
Type=notify
#ExecStart=/usr/sbin/dhcpd -f -cf /etc/dhcp/dhcpd.conf -user dhcpd -group dhcpd --no-pidExecStartPre=/bin/mkdir /run/dhcpd
ExecStartPre=/bin/touch /run/dhcpd/dhcpd.leases
ExecStartPre=/bin/chown -R dhcpd:dhcpd /run/dhcpdExecStart=/usr/sbin/dhcpd -f -cf /etc/dhcp/dhcpd.conf -lf /run/dhcpd/dhcpd.leases -user dhcpd -group dhcpd --no-pid enp3s0ExecStopPost=/bin/rm -fr /run/dhcpd[Install]
WantedBy=multi-user.target

修改 services文件的启动参数 ExecStart,增加命令行参数,内网接口 enp3s0

ExecStart=/usr/sbin/dhcpd -f -cf /etc/dhcp/dhcpd.conf -lf /run/dhcpd/dhcpd.leases -user dhcpd -group dhcpd --no-pid enp3s0

Samba,限制IP

[root@localhost ~]# cat /etc/samba/smb.conf
[global]workgroup = WORKGROUPnetbios name = Sambaserver string = Samba Server Version %vbind interfaces only = Yesinterfaces = lo enp3s0 192.168.0.2/24hosts allow = 127. 192.168.0.

这个就靠 smb.conf 配置文件本身来限制内网IP
 

参考:systemd 235 released [LWN.net]

Linux systemd资源控制初探 - 舰队 - 博客园

systemd.socket 中文手册 [金步国]

http://www.jinbuguo.com/systemd/systemd.resource-control.html
C

这篇关于Telnet tftp cvs 等IP限制在CentOS 7 Systemd的使用的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/677204

相关文章

使用Python实现图像LBP特征提取的操作方法

《使用Python实现图像LBP特征提取的操作方法》LBP特征叫做局部二值模式,常用于纹理特征提取,并在纹理分类中具有较强的区分能力,本文给大家介绍了如何使用Python实现图像LBP特征提取的操作方... 目录一、LBP特征介绍二、LBP特征描述三、一些改进版本的LBP1.圆形LBP算子2.旋转不变的LB

Maven的使用和配置国内源的保姆级教程

《Maven的使用和配置国内源的保姆级教程》Maven是⼀个项目管理工具,基于POM(ProjectObjectModel,项目对象模型)的概念,Maven可以通过一小段描述信息来管理项目的构建,报告... 目录1. 什么是Maven?2.创建⼀个Maven项目3.Maven 核心功能4.使用Maven H

Python中__init__方法使用的深度解析

《Python中__init__方法使用的深度解析》在Python的面向对象编程(OOP)体系中,__init__方法如同建造房屋时的奠基仪式——它定义了对象诞生时的初始状态,下面我们就来深入了解下_... 目录一、__init__的基因图谱二、初始化过程的魔法时刻继承链中的初始化顺序self参数的奥秘默认

SpringBoot使用GZIP压缩反回数据问题

《SpringBoot使用GZIP压缩反回数据问题》:本文主要介绍SpringBoot使用GZIP压缩反回数据问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录SpringBoot使用GZIP压缩反回数据1、初识gzip2、gzip是什么,可以干什么?3、Spr

Spring Boot 集成 Quartz并使用Cron 表达式实现定时任务

《SpringBoot集成Quartz并使用Cron表达式实现定时任务》本篇文章介绍了如何在SpringBoot中集成Quartz进行定时任务调度,并通过Cron表达式控制任务... 目录前言1. 添加 Quartz 依赖2. 创建 Quartz 任务3. 配置 Quartz 任务调度4. 启动 Sprin

Linux下如何使用C++获取硬件信息

《Linux下如何使用C++获取硬件信息》这篇文章主要为大家详细介绍了如何使用C++实现获取CPU,主板,磁盘,BIOS信息等硬件信息,文中的示例代码讲解详细,感兴趣的小伙伴可以了解下... 目录方法获取CPU信息:读取"/proc/cpuinfo"文件获取磁盘信息:读取"/proc/diskstats"文

Java使用SLF4J记录不同级别日志的示例详解

《Java使用SLF4J记录不同级别日志的示例详解》SLF4J是一个简单的日志门面,它允许在运行时选择不同的日志实现,这篇文章主要为大家详细介绍了如何使用SLF4J记录不同级别日志,感兴趣的可以了解下... 目录一、SLF4J简介二、添加依赖三、配置Logback四、记录不同级别的日志五、总结一、SLF4J

使用Python实现一个优雅的异步定时器

《使用Python实现一个优雅的异步定时器》在Python中实现定时器功能是一个常见需求,尤其是在需要周期性执行任务的场景下,本文给大家介绍了基于asyncio和threading模块,可扩展的异步定... 目录需求背景代码1. 单例事件循环的实现2. 事件循环的运行与关闭3. 定时器核心逻辑4. 启动与停

如何使用Nginx配置将80端口重定向到443端口

《如何使用Nginx配置将80端口重定向到443端口》这篇文章主要为大家详细介绍了如何将Nginx配置为将HTTP(80端口)请求重定向到HTTPS(443端口),文中的示例代码讲解详细,有需要的小伙... 目录1. 创建或编辑Nginx配置文件2. 配置HTTP重定向到HTTPS3. 配置HTTPS服务器

Java使用ANTLR4对Lua脚本语法校验详解

《Java使用ANTLR4对Lua脚本语法校验详解》ANTLR是一个强大的解析器生成器,用于读取、处理、执行或翻译结构化文本或二进制文件,下面就跟随小编一起看看Java如何使用ANTLR4对Lua脚本... 目录什么是ANTLR?第一个例子ANTLR4 的工作流程Lua脚本语法校验准备一个Lua Gramm