To enable UDP traffic on port 1194 for both incoming and outgoing connections on a Debian system, you need to configure your firewall settings. This can be done using iptables or ufw (Uncomplicated Firewall). Here are the steps for both methods:

Using iptables
  1. Install iptables (if not already installed):
sudo apt-get update
sudo apt-get install iptables
  • 1.
  • 2.
  1. Allow incoming UDP traffic on port 1194:
sudo iptables -A INPUT -p udp --dport 1194 -j ACCEPT
  • 1.
  1. Allow outgoing UDP traffic on port 1194:
sudo iptables -A OUTPUT -p udp --sport 1194 -j ACCEPT
  • 1.
  1. Save the iptables rules:
sudo sh -c "iptables-save > /etc/iptables/rules.v4"
  • 1.
Using ufw
  1. Install ufw (if not already installed):
sudo apt-get update
sudo apt-get install ufw
  • 1.
  • 2.
  1. Enable ufw:
sudo ufw enable
  • 1.
  1. Allow incoming UDP traffic on port 1194:
sudo ufw allow 1194/udp
  • 1.
  1. Allow outgoing UDP traffic on port 1194 (optional, usually ufw handles this automatically):
sudo ufw allow out 1194/udp
  • 1.
  1. Check ufw status to ensure the rule is added:
sudo ufw status
  • 1.
Verification

After configuring the firewall, you can verify that the rules are active by checking the firewall status:

  • For iptables:
sudo iptables -L -v -n
  • 1.
  • For ufw:
sudo ufw status verbose
  • 1.

These steps will ensure that UDP traffic on port 1194 is allowed in and out of your Debian system.

Server:

sudo tcpdump -i any port 1194 -XX

Client:
UDPSender.cpp

#include <WinSock2.h>
#include <WS2tcpip.h>
#include <stdio.h>

#pragma comment(lib, "Ws2_32.lib")

int main(int argc, char* argv[]) {
    // Validate command-line arguments
    if (argc != 4) {
        printf("Usage: %s <server_ip> <server_port> <message>\n", argv[0]);
        return 1;
    }

    const char* server_ip = argv[1];
    int server_port = atoi(argv[2]);
    const char* message = argv[3];

    // Initialize Winsock
    WSADATA wsaData;
    if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) {
        printf("WSAStartup failed. Error Code : %d", WSAGetLastError());
        return 1;
    }

    // Create socket
    SOCKET sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
    if (sockfd == INVALID_SOCKET) {
        printf("Socket creation failed. Error Code : %d", WSAGetLastError());
        WSACleanup();
        return 1;
    }

    // Server address structure
    sockaddr_in serverAddr;
    serverAddr.sin_family = AF_INET;
    serverAddr.sin_port = htons(server_port);
    inet_pton(AF_INET, server_ip, &serverAddr.sin_addr);

    // Send UDP packet
    int bytesSent = sendto(sockfd, message, strlen(message), 0, (sockaddr*)&serverAddr, sizeof(serverAddr));
    if (bytesSent == SOCKET_ERROR) {
        printf("Send failed. Error Code : %d", WSAGetLastError());
        closesocket(sockfd);
        WSACleanup();
        return 1;
    }

    printf("UDP packet sent.\n");

    // Close socket
    closesocket(sockfd);
    WSACleanup();
    return 0;
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.

E:\Projects\VS_Projects\UDPSender\Debug\UDPSender.exe 47.93.27.106 1194 “Hello. This is a test message for UDP 1194.”