Table des matières
0 billet(s) pour février 2026
NFS - Exécuter NFSv3 derrière un pare-feu
Source : http://underpop.online.fr/l/linux/en/centos/s2-sysconfig-nfs.htm
NFS requires portmap/rcpbind, which dynamically assigns ports for RPC services. This causes problems for configuring firewall rules. To overcome this problem, use the /etc/sysconfig/nfs file to control which ports the required RPC services run on.
Deprecate /etc/sysconfig/nfs and only use /etc/nfs.conf to configure NFS daemons
The /etc/sysconfig/nfs may not exist by default on all systems. If it does not exist, create it and add the following variables (alternatively, if the file exists, un-comment and change the default entries as required):
MOUNTD_PORT=x
control which TCP and UDP port mountd (rpc.mountd) uses. Replace x with an unused port number.
STATD_PORT=x
control which TCP and UDP port status (rpc.statd) uses. Replace x with an unused port number.
LOCKD_TCPPORT=x
control which TCP port nlockmgr (rpc.lockd) uses. Replace x with an unused port number.
LOCKD_UDPPORT=x
control which UDP port nlockmgr (rpc.lockd) uses. Replace x with an unused port number.
If NFS fails to start, check /var/log/messages. Normally, NFS will fail to start if you specify a port number that is already in use. After editing /etc/sysconfig/nfs restart the NFS service by running the service nfs restart command. Run the rpcinfo -p command to confirm the changes.
To configure a firewall to allow NFS:
- Allow TCP and UDP port 2049 for NFS.
- Allow TCP and UDP port 111 (portmap/sunrpc).
- Allow the TCP and UDP port specified with
MOUNTD_PORT=“x” - Allow the TCP and UDP port specified with
STATD_PORT=“x” - Allow the TCP port specified with
LOCKD_TCPPORT=“x” - Allow the UDP port specified with
LOCKD_UDPPORT=“x”
Network Namespaces - netns - /etc/hosts que pour une appli spécifique grâce aux espaces de noms
Voir :
- nsenter
Création de l'espace de nom
ip netns add NETNS1 mkdir -p /etc/netns/NETNS1/ cp -p /etc/hosts /etc/netns/NETNS1/ echo 127.0.0.2 srv-test1 >> /etc/netns/NETNS1/hosts ip netns exec NETNS1 getent hosts srv-test1
ça résout mais ça ne ping pas
# ip netns exec NETNS1 ping srv-test1 connect: Network is unreachable
Corrigeons ça
Configuration de localhost
ip link add veth1 type veth peer name vpeer1 ip netns exec NETNS1 ip link set lo up
# ip netns exec NETNS1 ping srv-test1 PING srv-test1 (127.0.0.2) 56(84) bytes of data. 64 bytes from srv-test1 (127.0.0.2): icmp_seq=1 ttl=64 time=0.072 ms
Configuration du routage
Pour les autres destinations
ip link set veth1 netns NETNS1 # Ne semble pas nécessaire #echo 1 > /proc/sys/net/ipv4/ip_forward ip netns exec NETNS1 ip addr add 172.16.1.1/31 dev veth1 ip link set vpeer1 up ip netns exec NETNS1 ip link set veth1 up ip netns exec NETNS1 ip route add default via 172.16.1.1
Bridge
ip link add br0 type bridge ip link set br0 up ip link set vpeer1 master br0 ip addr add 172.16.1.0 dev br0 ip route add 172.16.1.0/31 dev br0
Nettoyage
ip netns delete NETNS1 rm -rf /etc/netns/NETNS1/
Network - How to retrieve packet drop reasons in the Linux kernel
Voir aussi :
Understanding why a packet drops in the Linux kernel is not always easy. The networking stack is wide and reasons to refuse a given packet are multiple and include invalid data from a protocol, firewall rules, wrong checksum, full queues, qdisc or XDP actions, and many more reasons. It is possible to look at indicators such as MIB counters and statistic counters, but often those are generic and triggered for different reasons, but most importantly their coverage is small, and it's impossible to match a specific packet to a given counter increase.
Socket buffer drop reasons
The socket buffer, SKB (struct sk_buff) is the main data structure representing a packet in the Linux kernel networking stack. When a packet is dropped in the Linux kernel, in most cases, it means its associated socket buffer has dropped. In recent versions of the Linux kernel, starting in v5.17, socket buffers can be dropped with an associated reason. This was introduced in upstream commit c504e5c2f964 (“net: skb: introduce kfree_skb_reason()”).
Using this commit and later additions, kernel developers are now able to specify why a given packet dropped. In the following example, a packet is dropped because no socket was found:
- kfree_skb(skb); + kfree_skb_reason(skb, SKB_DROP_REASON_NO_SOCKET);
Using tools to retrieve drop reasons
The SKB drop reason can be retrieved in a few different ways, depending on which you are comfortable using, what is available on a given system, and the end goal (some solutions have more flexibility than others).
The main interface to retrieve the drop reason is the skb:kfree_skb tracepoint. It provides a user readable text for all drop reasons. A good way to attach to this tracepoint is to use perf as follows:
# perf record -e skb:kfree_skb curl https://localhost # given no server listens on localhost:443/tcp.
# perf script
curl 883 [001] 340.799805: skb:kfree_skb: skbaddr=0xffff88811f6a7068 protocol=2048 location=tcp_v4_rcv+0x157 reason: NO_SOCKET
curl 883 [001] 340.800860: skb:kfree_skb: skbaddr=0xffff88811f6a6de8 protocol=34525 location=tcp_v6_rcv+0x137 reason: NO_SOCKET
You can see why the two packets where dropped in tcp_v4_rcv and tcp_v6_rcv because no socket was found and we do not have a server listening on localhost:443/tcp.
We can also use other tools such as bpftrace to get the drop reason, which would give us more flexibility, the drawback being the reason isn't converted to a human readable string:
# bpftrace -e 'tracepoint:skb:kfree_skb {printf("%s: %d\n", comm, args->reason)}' -c 'curl https://localhost'
Attaching 1 probe...
curl: 3
curl: 3
curl: (7) Failed to connect to localhost port 443 after 2 ms: Couldn't connect to server
Another method is the dropwatch, an interactive tool to monitor packets dropped in the Linux kernel. When using the packet alert mode, drop reasons are included.
# dropwatch -l kas Initializing kallsyms db dropwatch> set alertmode packet Setting alert mode Alert mode successfully set dropwatch> start Enabling monitoring... Kernel monitoring activated. Issue Ctrl-C to stop monitoring drop at: tcp_v4_rcv+0x157/0x1630 (0xffffffff8abc4f87) origin: software input port ifindex: 1 timestamp: Thu Feb 23 18:03:36 2023 370138884 nsec protocol: 0x800 length: 74 original length: 74 drop reason: NO_SOCKET drop at: tcp_v6_rcv+0x137/0x14f0 (0xffffffff8ad91b37) origin: software input port ifindex: 1 timestamp: Thu Feb 23 18:03:36 2023 372335338 nsec protocol: 0x86dd length: 94 original length: 94 drop reason: NO_SOCKET
Note:The skb_drop_reason enum defines core drop reasons. It is an internal definition, and the actual value of all its members is not guaranteed to be constant over time. This feature is recent and some of the drop reasons were reordered during development. There is also work ongoing for supporting drop reasons from different subsystems. You should either use tools directly providing the drop reason in a text format (perf or dropwatch) or take the right drop reasons definition as a reference when retrieving the drop reason in a numeric way (bpftrace).
Summary
Not all drop places in the Linux kernel are covered. Converting them to this new facility takes time and resources. There is progress upstream with more additions. Currently, more than 70 reasons are supported. There is also an effort to support more than the core networking subsystem.
SKB drop reasons are now available in Red Hat Enterprise Linux starting with RHEL 8.8 and RHEL 9.2.
Apache restriction par adresse IP
A mettre dans la conf du vhost
<Location /> Order deny,allow Deny from all Allow from 127.0.0.1 Allow from 192.168.1.0/24 </Location>
Commande nbtstat sous GNU/Linux ?
Voir aussi : nbtscan
Nbtstat est une commande sous ouidoze qui : “Affiche les statistiques du protocole et les connexions TCP/IP actuelles utilisant NBT (NetBIOS sur TCP/IP)”
Les options '-A' et '-a' sont couramment utilisées :
- -a (état carte) Liste la table de noms de l'ordinateur distant (nom connu).
- -A (état carte) Liste la table de noms d'ordinateurs distants (adresse IP).
Équivalent sous GNU/Linux
Sous ouindoze
nbtstat -A 192.168.1.22
Sous GNU/Linux
nmblookup -A 137 192.168.1.22
sudo nmap -sU --script nbstat.nse -p 137 192.168.1.22
Notes
Voir aussi
sudo nmap -T5 -PN -p 445 -sS -n --min-hostgroup 8192 --min-rtt-timeout 1000ms \ --min-parallelism 4096 --script=nbstat <target>
Source : https://blog.skullsecurity.org/2009/nbstatnse-a-replacement-for-nbtscan-and-others
Sous ouindoze
nbtstat -a COMPUTERNAME
Sous GNU/Linux
nmap -p 445 -Pn -script=smb-os-discovery COMPUTERNAME
Pb
J'ai l'erreur suivante avec nmap 5.00 (Debian squeeze) :
Illegal Argument to -P, use -PN, -PO, -PI, -PB, -PE, -PM, -PP, -PA, -PU, -PT, or -PT80 (or whatever number you want for the TCP probe destination port) QUITTING!
Mais ça fonctionne avec nmap 6.00 (Debian Wheezy)
Voir le paquet Debian apt:nbtscan
