当 rsync/scp 不可用时,从系统传输文件或者 sosreport。

在红帽企业Linux5.x、6.x和7.x中,当ssh和rsync不可用时,可以通过配置iptables防火墙规则和使用nc工具来传输sosreport。在接收和发送系统之间,需要打开一个未使用的端口,允许来自救援系统的IP地址的流量,并使用nc监听和发送sosreport文件。在每个版本中,具体步骤涉及检查和修改iptables配置或firewalld的丰富规则,以及在发送端生成sosreport并将其发送到接收端的特定端口。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

环境

问题

  • 文件需要转移到另一个系统,但是sshrsync未设置和/或允许。
  • 一个sosreport需要转移到另一个系统。

红帽企业 Linux 5.x

配置 iptables

笔记 如果您的环境中没有使用 iptables,您可以跳到“配置 nc”

sh-3.2# ip -4 a
3: eth0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop qlen 1000
    inet 192.168.122.3/24 scope global eth0
  • 检查系统上现有的链以接收sosreport# iptables -L -n -v
# iptables -L -n -v
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         
 2594 3484K RH-Firewall-1-INPUT  all  --  *      *       0.0.0.0/0            0.0.0.0/0           

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 RH-Firewall-1-INPUT  all  --  *      *       0.0.0.0/0            0.0.0.0/0           

Chain OUTPUT (policy ACCEPT 2174 packets, 307K bytes)
 pkts bytes target     prot opt in     out     source               destination         

Chain RH-Firewall-1-INPUT (2 references)
 pkts bytes target     prot opt in     out     source               destination         
   32  3822 ACCEPT     all  --  lo     *       0.0.0.0/0            0.0.0.0/0           
    0     0 ACCEPT     icmp --  *      *       0.0.0.0/0            0.0.0.0/0           icmp type 255 
    0     0 ACCEPT     esp  --  *      *       0.0.0.0/0            0.0.0.0/0           
    0     0 ACCEPT     ah   --  *      *       0.0.0.0/0            0.0.0.0/0           
    0     0 ACCEPT     udp  --  *      *       0.0.0.0/0            224.0.0.251         udp dpt:5353 
    0     0 ACCEPT     udp  --  *      *       0.0.0.0/0            0.0.0.0/0           udp dpt:631 
    0     0 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp dpt:631 
 2561 3480K ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED 
    1    60 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:22 
    0     0 REJECT     all  --  *      *       0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited
  • 插入新的初始规则INPUT或子链INPUT使用前面确定的 Rescue 系统的 IP 地址,其形式为:
  • # iptables -I <chain name> 1 -p tcp --dport <port to receive traffic> -s <IP address of Rescue system> -j ACCEPT 笔记 与 dport 关联的端口可以是任意的,但建议使用未使用的大号端口以避免任何冲突的网络流量
  • 鉴于上述设置,运行:# iptables -I "RH-Firewall-1-INPUT" 1 -p tcp --dport 12345 -s 192.168.122.3 -j ACCEPT

配置数控

接收服务器

  • 确保这件事# nc安装在接收主机上。
  • 可执行文件来自nc转数
# rpm -qf $(which nc)
nc-1.84-10.fc6

  • 该软件包应默认安装在系统上
  • 通过运行确定接收主机的 IP 地址# ip -4 a
  • 在上述 IP 链指定的端口上启动监听器,如果适用,否则建议您选择未使用的高编号端口
  • 重定向输出# nc命令到文件
  • # nc -l 12345 > /tmp/sosreport-$(date +%F).tar.bz2

发送服务器

  • 从救援环境生成 sosreport
  • # nc存在于救援环境中/usr/bin/nc
  • 连接到接收主机的开放端口,形式为
  • # nc <ip address> <port>
  • 发送sosreport通过将标准输入重定向到接收系统# nc
  • # nc 192.168.122.149 12345 < /mnt/sysimage/tmp/sosreport-jdoe.0123456789.tar.bz2

接收服务器

  • 删除之前添加的ipchain:# iptables -D "RH-Firewall-1-INPUT" 1

红帽企业 Linux 6.x

配置 iptables

笔记 如果您的环境中没有使用 iptables,您可以跳到“配置 nc”

bash-4.1# ip -4 a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
    inet 127.0.0.1/8 scope host lo
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    inet 192.168.122.3/24 scope global eth0
  • 检查系统上现有的链以接收sosreport# iptables -L -n -v
# iptables -L -n -v
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         
 1173  463K ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED 
    0     0 ACCEPT     icmp --  *      *       0.0.0.0/0            0.0.0.0/0           
    0     0 ACCEPT     all  --  lo     *       0.0.0.0/0            0.0.0.0/0           
    0     0 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:22 
    1   328 REJECT     all  --  *      *       0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited 

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 REJECT     all  --  *      *       0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited 

Chain OUTPUT (policy ACCEPT 712 packets, 129K bytes)
 pkts bytes target     prot opt in     out     source               destination 
  • 使用之前以以下形式确定的 Rescue 系统的 IP 地址,将新的初始规则插入 INPUT 或 INPUT 的子链:
  • # iptables -I <chain name> 1 -p tcp --dport <port to receive traffic> -s <IP address of Rescue system> -j ACCEPT 笔记 与 dport 关联的端口可以是任意的,但建议使用未使用的大号端口以避免任何冲突的网络流量
  • 鉴于上述设置,运行:# iptables -I INPUT 1 -p tcp --dport 12345 -s 192.168.122.3 -j ACCEPT

配置 nc/ncat

接收服务器

  • 确保# nc或者# ncat安装在接收主机上。
  • 可执行文件分别来自 nc 和 nmap rpm
# rpm -qf $(which nc)
nc-1.84-24.el6.x86_64
# rpm -qf $(which ncat)
nmap-5.51-4.el6.x86_64
  • nc软件包在 RHEL 6.X 存储库中可用
  • 通过运行确定接收主机的 IP 地址# ip -4 a
  • 在上述 IP 链指定的端口上启动监听器,如果适用,否则建议您选择未使用的高编号端口
  • 重定向输出# nc命令到文件
  • # nc -l 12345 > /tmp/sosreport-$(date +%F).tar.xz

发送服务器

  • 从救援环境生成 sosreport
  • # nc存在于救援环境中/usr/bin/nc
  • 连接到接收主机的开放端口,形式为
  • # nc <ip address> <port>
  • 发送sosreport通过将标准输入重定向到接收系统# nc
  • # nc 192.168.122.149 12345 < /mnt/sysimage/tmp/sosreport-jdoe.0123456789.tar.xz

接收服务器

  • 删除之前添加的ipchain:# iptables -D INPUT 1

红帽企业 Linux 7.x

配置防火墙

笔记 在 RHEL 7 中默认不使用 iptables。而是使用 firewalld 作为防火墙管理器。如果您不使用 firewalld,请跳至“配置 nc” 如果您在您的环境中使用 iptables,则为 RHEL 6 指定的现有指令也适用于 RHEL 7

sh-4.2# ip -4 a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000

    inet 192.168.122.7/24 scope global eth0
       valid_lft forever preferred_lft forever
  • 检查系统上的现有规则,包括丰富规则,以接收sosreport# firewall-cmd --list-all
# firewall-cmd --list-all
public (default, active)
  interfaces: eth0
  sources: 
  services: dhcpv6-client ssh
  ports: 
  masquerade: no
  forward-ports: 
  icmp-blocks: 
  rich rules: 
        rule port port="6000" protocol="tcp" drop

  • 使用前面确定的 Rescue 系统的 IP 地址添加新的丰富规则,其形式为:
  • # firewall-cmd --add-rich-rule 'rule family=ipv4 source address="source address" port port="port number" protocol=tcp accept' 笔记 与“端口”关联的端口可以是任意的,但建议使用未使用的大号端口以避免任何冲突的网络流量
  • 鉴于上述设置,运行:# firewall-cmd --add-rich-rule 'rule family=ipv4 source address="192.168.122.7" port port=12345 protocol=tcp accept'

配置数控

接收服务器

  • 确保# nc安装在接收主机上。
  • 可执行文件来自 nmap-ncat rpm
# rpm -qf $(which nc)
nmap-ncat-6.40-7.el7.x86_64
  • nc 包在 RHEL 7.X 存储库中可用
  • 通过运行确定接收主机的 IP 地址# ip -4 a
  • 在上述firewalld规则指定的端口上启动监听器,如果适用,否则建议您选择一个未使用的高编号端口
  • 重定向输出# nc命令到文件
  • # nc -l 12345 > /tmp/sosreport-$(date +%F).tar.xz

发送服务器

  • 从救援环境生成 sosreport
  • # nc救援环境中不存在。 注意有必要将本地安装的 dvd/iso 设置为存储库
  • 安装 nmap-ncat rpm:# yum install nmap-ncat
  • 连接到接收主机的开放端口,形式为
  • # nc <ip address> <port>
  • 发送sosreport通过将标准输入重定向到接收系统# nc
  • # nc 192.168.122.149 12345 < /mnt/sysimage/var/tmp/sosreport-jdoe.0123456789.tar.xz

接收服务器

  • 删除之前添加的 firewalld 富规则:# firewall-cmd --remove-rich-rule 'rule family=ipv4 source address="192.168.122.7" port port=12345 protocol=tcp accept'

根本原因

  • nc /ncat是一种网络实用程序,具有大量功能,包括通过网络读取和写入数据的能力。
  • 通过打开特定端口ncat, 数据可以在两个系统之间传输而无需ssh,rsync , 或者scp.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值