AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 765750
Accepted
Abc Xyz
Abc Xyz
Asked: 2016-03-24 15:13:10 +0800 CST2016-03-24 15:13:10 +0800 CST 2016-03-24 15:13:10 +0800 CST

iptables 在通过 scp 复制文件时将数据包标记为错误编号

  • 772

[案例1]当从服务器(在客户端)复制文件到客户端时,数据包被标记为3(root)不正确。

[案例2]将文件从服务器(在服务器上)复制到客户端时,数据包被标记为正确的 1003 (test1)。

服务器 ip 192.168.0.16,test1 是服务器用户。

客户端ip 192.168.0.10,客户端为客户端用户。

[情况1]

[email protected]:~$ scp -P 22 [email protected]:/home/test1/archlinux-bootstrap-2016.03.01-x86_64.tar.gz /tmp/

ps检查,同时复制:

[email protected]:~$ ps aux | grep scp
root      1653  0.1  0.0  32668  4408 ?        Ss   19:31   0:00  \_ sshd: test1 [priv]
test1      1655  3.0  0.0  36104  6912 ?        S    19:31   0:00      \_ sshd: test1@notty
test1      1656  1.3  0.0  27516  2648 ?        Ss   19:31   0:00          \_ scp -f /home/test1/archlinux-bootstrap-2016.03.01-x86_64.tar.gz

bmon [class 1:3 是 root 用户] [class 1:1003 是 test1 用户]

  imq0 (outgoing)              │   1.17MiB    818      │   1.12MiB    781
    qdisc 1: (htb)             │      0         0      │   1.12MiB    781
      cls :3 (fw)              │      0         0      │      0         0
      cls :3eb (fw)            │      0         0      │      0         0
      class 1:1 (htb)          │      0         0      │   1.12MiB    781   99%
        class 1:2 (htb)        │      0         0      │    430B        1    0%
        class 1:3 (htb)        │      0         0      │   1.12MiB    780   208%
        class 1:1003 (htb)     │      0         0      │      0         0    0%
        class 1:5 (htb)        │      0         0      │      0         0    0%
        class 1:6 (htb)        │      0         0      │      0         0    0%

[案例2]

[email protected]:~$ scp -P 22 archlinux-bootstrap-2016.03.01-x86_64.tar.gz [email protected]:~/

ps检查,同时复制:

[email protected]:~$ ps aux | grep scp
root      1637  0.0  0.0  32668  4400 ?        Ss   19:29   0:00  \_ sshd: test1 [priv]
test1      1639  0.0  0.0  32668  3240 ?        S    19:30   0:00      \_ sshd: test1@pts/3
test1      1640  0.0  0.0  20540  3296 pts/3    Ss   19:30   0:00          \_ -bash
test1      1650  0.0  0.0  27516  2640 pts/3    S+   19:30   0:00              \_ scp -P 22 archlinux-bootstrap-2016.03.01-x86_64.tar.gz [email protected]:~/
test1      1651  0.0  0.0  30636  6748 pts/3    S+   19:30   0:00                  \_ /usr/bin/ssh -x -oForwardAgent=no -oPermitLocalCommand=no -oClearAllForwardings=yes -p 22 -l

bmon [class 1:3 是 root 用户] [class 1:1003 是 test1 用户]

  imq0                         │ 142.83KiB    103      │  98.50KiB     68
    qdisc 1: (htb)             │      0         0      │  98.50KiB     68
      cls :3eb (fw)            │      0         0      │      0         0
      cls :3 (fw)              │      0         0      │      0         0
      class 1:1 (htb)          │      0         0      │  98.50KiB     68    1%
        class 1:2 (htb)        │      0         0      │    533B        2    0%
        class 1:3 (htb)        │      0         0      │      0         0    0%
        class 1:1003 (htb)     │      0         0      │  97.97KiB     66   100%
        class 1:5 (htb)        │      0         0      │      0         0    0%

iptables 规则:

# IN
  iptables -t mangle -A PREROUTING -i eth0 -j IMQ --todev 1
  iptables -t mangle -A PREROUTING -j CONNMARK  --restore-mark
# OUT
  iptables -t mangle -N IMQ-OUT
  iptables -t mangle -A POSTROUTING -o eth0 -j IMQ-OUT
  iptables -t mangle -A IMQ-OUT -o eth0 -m owner --uid-owner root -j MARK --set-mark 3
  iptables -t mangle -A IMQ-OUT -o eth0 -m owner --uid-owner root -j RETURN
  iptables -t mangle -A IMQ-OUT -o eth0 -m owner --uid-owner test1 -j MARK --set-mark 1003
  iptables -t mangle -A IMQ-OUT -o eth0 -m owner --uid-owner test1 -j RETURN
  iptables -t mangle -A POSTROUTING -j CONNMARK  --save-mark
  iptables -t mangle -A POSTROUTING -o eth0 -j IMQ --todev 0

有人可以解释一下为什么 [Case1] 服务器认为传出连接是根连接,即使ps显示用户 test1 也是如此?

现在,我正在尝试按用户使用 cgroup 来塑造流量。

与 cgroup 的情况相同。

echo '1003' > /cgroup/cpu_mem_blkio/users/test1/net_cls.classid
iptables -t mangle -A IMQ-OUT -o eth0 -m cgroup --cgroup 1003 -j MARK --set-mark 1003
iptables
  • 1 1 个回答
  • 128 Views

1 个回答

  • Voted
  1. Best Answer
    Anderson Medeiros Gomes
    2016-03-27T07:08:59+08:002016-03-27T07:08:59+08:00

    在[Case1]中,文件传输过程中连接sshd到客户端的socket不属于scp进程。相反,它属于sshdroot 拥有的进程。因此,设定标记的规则3占上风。


    看我的例子。首先,我从客户端启动一个复制任务:

    [amg1127@amg1127-laptop /tmp]$ scp -4 amg1127-sala:/tmp/virtualbox-machine.vdi .
    virtualbox-machine.vdi                        0% 5488KB   1.4MB/s   55:47 ETA^
    

    然后,我在服务器中计算出与副本相关的进程和套接字。

    [root@amg1127-sala /tmp]# lsof /tmp/virtualbox-machine.vdi
    COMMAND   PID    USER   FD   TYPE DEVICE   SIZE/OFF     NODE NAME
    scp     12107    1000    3r   REG  254,5 4824498176 20439792 /tmp/virtualbox-machine.vdi
    
    [root@amg1127-sala /tmp]# netstat -pan | grep ':22'
    tcp   0      0 0.0.0.0:22         0.0.0.0:*           LISTEN      1029/sshd           
    tcp   0 195936 192.168.254.10:22  192.168.254.9:59574 ESTABLISHED 12089/sshd: amg1127 
    tcp6  0      0 :::22              :::*                LISTEN      1029/sshd           
    
    [root@amg1127-sala /tmp]# ps -C sshd -C scp -o uid,euid,pid,ppid,cmd
     UID  EUID   PID  PPID CMD
       0     0  1029     1 /usr/bin/sshd -D
       0     0 12089  1029 sshd: amg1127 [priv]
    1000  1000 12106 12089 sshd: amg1127@notty
    1000  1000 12107 12106 scp -f /tmp/virtualbox-machine.vdi
    

    注意:

    1. lsof显示读取/tmp/virtualbox-machine.vdi文件的scp进程是 PID 为12107且所有者为的进程1000。
    2. netstat显示将文件数据发送到远程客户端的套接字是一个sshd进程,其 PID12089和所有者是0。

    这两个进程可能都通过匿名管道交换数据。

    • 1

相关问题

  • OpenVPN 的 Linux IP 转发 - 正确的防火墙设置?

  • iptables 单个规则中的多个源 IP

  • 存储 iptables 规则的规范方法是什么

  • 使用 iptables 和 dhcpd 进行端口转发

  • 根据 Apache 日志数据自动修改 iptables 以阻止行为不良的客户端

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve