Replacing TCP Wrappers in RHEL 8

在Red Hat Enterprise Linux 8中,TCP Wrappers包已弃用。可使用Firewalld作为防火墙层面的替代方案。示例展示了允许10.1.1.0/24网络的SSH访问,阻止其他网络。可创建新防火墙区域并启用SSH,重新加载防火墙使配置生效。

https://access.redhat.com/solutions/3906701

 SOLUTION 已验证 - 已更新 2019年二月21日09:58 - 

English 

环境

  • Red Hat Enterprise Linux 8

问题

  • The TCP Wrappers package has been deprecated in RHEL 7 and therefore it will not be available in RHEL 8 or later RHEL releases.

决议

  • Firewalld can be used as a firewall level replacement for TCP Wrappers.

  • This example allows SSH for the 10.1.1.0/24 network and blocks it for all others.

firewalld

  • Firewalld operates at the firewall layer and can be used to restrict access to a given service. One approach is to create a new firewall zone for the 10.1.1.0/24 network and enable SSH in the new zone.

  • firewalld enables SSH in the default (public) zone by default. To only allow 10.1.1.0/24 SSH, first needs to be removed from the default zone. For other services, this step can be skipped.

Raw

# firewall-cmd --permanent --remove-service=ssh
  • You can now create the new zone and add the SSH service.

Raw

# firewall-cmd --permanent --new-zone=mysshzone
# firewall-cmd --permanent --zone=mysshzone --add-source=10.1.1.0/24
# firewall-cmd --permanent --zone=mysshzone --add-service=ssh
  • Then, reload the firewall to make the new configuration active.

Raw

# firewall-cmd --reload
### 替换无效字符或值的方法 在处理字符串时,如果需要替换其中的无效字符或值,可以采用多种方法来实现这一目标。以下是几种常见的解决方案: #### 方法一:使用正则表达式过滤无效字符 通过 `String.replaceAll()` 或其他编程语言中的正则表达式功能,可以高效地移除或替换不符合条件的字符。 ```java // 使用 Java 的 String.replaceAll() 来替换所有非数字字符 String input = "abc123!@#"; String result = input.replaceAll("[^0-9\\.\\+\\-eE]", ""); // 只保留有效数值字符 ``` 此代码片段会将输入字符串中所有的非法字符替换为空字符串,仅留下有效的数值字符[^1]。 --- #### 方法二:逐字符验证并构建新字符串 对于更复杂的场景,可以通过遍历字符串中的每一个字符,并判断其合法性后再决定是否将其加入新的字符串中。 ```python def filter_invalid_characters(input_string): allowed_chars = set('0123456789.+eE') # 定义允许的字符集合 output = ''.join([char for char in input_string if char in allowed_chars]) return output input_string = "abc123!@#" result = filter_invalid_characters(input_string) print(result) # 输出: 123 ``` 这种方法能够灵活控制哪些字符被认为是合法的[^3]。 --- #### 方法三:编码转换与错误处理 当涉及不同编码之间的转换时,可能遇到无法解码的情况。此时可利用 Python 中的 `unicode()` 函数或其他类似的工具指定如何处理这些异常情况。 ```python try: decoded_string = bytes_object.decode(encoding='utf-8', errors='strict') except ValueError as e: print(f"Decoding failed due to invalid characters: {e}") ``` 这里设置了 `'strict'` 错误模式,在发现任何不可接受的字符时都会抛出异常;也可以改为 `'ignore'` 或 `'replace'` 模式以忽略或者替代这些问题字符[^2]。 --- #### 性能考量 需要注意的是,不同的替换方式可能会带来显著的性能差异。例如,在某些情况下多次调用简单的 `replace()` 方法相较于一次性执行复杂匹配操作如 `replaceAll()` 而言效率较低[^4]。 因此,在实际应用过程中应当综合考虑需求的具体特点以及运行环境等因素选择最合适的方案。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值