How netcat can`t receive UDP packets?

0

I have a simple UDP device (ENC28J60 ) connected to my computer with a direct cable. The device configured to send UDP packet to 192.168.133.1 IP, 6661 port.

The computer ,Fedora 22 OS, interface name is enp7s0. When an IP address assigned to the interface, tcpdump hangs, netcat silent. When no IP address assigned to the interface, netcat silent (no output), tcpdump receive packets.

The packets really comes from a device, I can see with tcpdump, only when the interface is UP, but no IP address assigned to.

First try to bring up the interface with an IP address.:

[root@d7520 ~]#  nmcli connection up toArd                                                                          
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/20)
[root@d7520 ~]# ip a s dev enp7s0                            
2: enp7s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 74:86:7a:1e:e0:85 brd ff:ff:ff:ff:ff:ff
    inet 192.168.133.1/24 brd 192.168.133.255 scope global enp7s0
       valid_lft forever preferred_lft forever
    inet6 fe80::7686:7aff:fe1e:e085/64 scope link 
       valid_lft forever preferred_lft forever

Try with netcat and tcpdump. No answer. tcpdump hangs.

[root@d7520 ~]# ncat -u -l 6661                                                                                                                      
^C
[root@d7520 ~]# tcpdump -vvv -i enp7s0 -X
tcpdump: listening on enp7s0, link-type EN10MB (Ethernet), capture size 262144 bytes


[root@d7520 ~]# nc -v -l -u 6661                                                                                                                                                                                                              
Ncat: Version 6.47 ( http://nmap.org/ncat )
Ncat: Listening on :::6661
Ncat: Listening on 0.0.0.0:6661
^C

Now , try to remove the IP address. tcpdump got the UDP packets, but netcat still silent.:

[root@d7520 ~]# nmcli connection down toArd 
Connection 'toArd' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/21)

 [root@d7520 ~]# ip a s dev enp7s0
2: enp7s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 74:86:7a:1e:e0:85 brd ff:ff:ff:ff:ff:ff
[root@d7520 ~]# tcpdump -vvv -i enp7s0 -X                                                                                                                     
tcpdump: listening on enp7s0, link-type EN10MB (Ethernet), capture size 262144 bytes
13:41:39.423449 IP (tos 0x0, ttl 64, id 0, offset 0, flags [DF], proto UDP (17), length 37)
    192.168.133.2.6660 > 192.168.133.1.6661: [udp sum ok] UDP, length 9
        0x0000:  4500 0025 0000 4000 4011 af73 c0a8 8502  E..%..@.@..s....
        0x0010:  c0a8 8501 1a04 1a05 0011 0630 7465 7374  ...........0test
        0x0020:  2031 3233 0000 0000 0000 0000 0000       .123..........
^C
1 packet captured
1 packet received by filter
0 packets dropped by kernel

g1ra

Posted 2015-09-18T12:05:13.997

Reputation: 1

Answers

0

I am not sure this is your problem, but why are you using nmcli in the first place? nmcli is the network-manager command-line interface, which is much more than you bargained for in trying to bring up your interfaces.

If I were you, I would proceed as follows. As sudo:

         service network-manager stop  # halt NM
         ip link set dev enp7s0 down   # bring the interface down, in order to...
         ip addr flush dev enp7s0      # ... get rid of its ip address

Either a manual configuration...

         ip addr add 192.168.133.133/24 dev enp7s0 # we give it a brand new address...
         ip link set dev enp7s0 up     # now we try again...
         ip route add default via 192.168.133.1 # and a gateway

or an automatic one:

         ip link set dev enp7s0 up
         dhclient -v enp7s0

(Depending on your distro, you may have to leave out the -v flag).

Now I would try again, and both tcpdump and nc should be working.

MariusMatutiae

Posted 2015-09-18T12:05:13.997

Reputation: 41 321