我不会详细介绍如何设置SELinux或如何创建SELinux策略.
This可能是熟悉SELinux的良好起点.
要解决SELinux的问题,请尝试以下方法:
>将类型分配给您要限制的网络接口
# Assign a type to the whole interface
semanage interface -a -t foo_netif_t eth2
>为通过接口的流量分配标签
netlabelctl unlbl add interface:eth2 address:0.0.0.0/0 label:system_u:object_r:foo_peer_t:s0
netlabelctl unlbl add interface:eth2 address:::/0 label:system_u:object_r:foo_peer_t:s0
此示例将类型foo_peer_t分配给所有IPv4和IPv6流量.
>添加规则以允许数据包流
交通进入
allow user_t foo_netif_t:netif ingress;
allow user_t foo_peer_t:node recvfrom;
交通离开
allow user_t foo_netif_t:netif egress;
allow user_t foo_peer_t:node sendto;
将user_t替换为分配给您要限制的用户的类型.
参考文献: