Mac与Kali虚拟机间Netcat双向连接异常排查求助
Hey there, let's figure out why you're hitting that "Connection refused" error when trying to connect from your Mac to your Kali VM's netcat listener. Here are the most common issues to check and fix step by step:
Check Kali's firewall settings
Kali's default firewall (ufw) might be blocking incoming connections on port 1234. First, runsudo ufw statusin your Kali terminal—if it shows "active", that's likely the problem. You can either temporarily disable it withsudo ufw disableto test, or add a rule to allow traffic on port 1234:sudo ufw allow 1234/tcp. If you're using iptables instead, runsudo iptables -Lto check for rules that might be rejecting incoming traffic on that port.Verify the netcat listener is actually running correctly
Double-check that yournc -lv 1234command on Kali is working as expected. You should see output likelistening on [any] 1234 ...to confirm it's listening on all interfaces. Also, usess -tulpn | grep 1234to make sure the port is actually occupied by nc—sometimes another program might be using the port, or the listener might be bound only to the loopback address (127.0.0.1), which would prevent external connections.Check your VM's network mode
This is a super common culprit. If your Kali VM is using NAT mode, it's on a private network that your Mac can't directly reach. Switch it to Bridge Mode in your virtualization software (like VirtualBox or VMware)—this will give Kali an IP address on the same local network as your Mac, making direct connections possible. Also, confirm you're using the correct IP: runip ain Kali to get its actual local IP, not the loopback (127.0.0.1) or a NAT-internal IP.Rule out Mac-side firewall/security software interference
Even though you're connecting outward from your Mac, some firewall or third-party security tools might block outbound traffic to port 1234. Try temporarily disabling Mac's built-in firewall (go to System Settings > Network > Firewall) and test the connection again. If that works, you can add an exception for netcat or port 1234 later.Double-check your nc command syntax on Mac
Make sure you're typing the command correctly:nc ip.of.my.kali 1234. If you're having issues with IPv6, try forcing IPv4 withnc -4 ip.of.my.kali 1234—sometimes Mac defaults to IPv6 which might not be set up properly for your VM.
备注:内容来源于stack exchange,提问作者edamondo

