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
- Install
iptables
(if not already installed):
sudo apt-get update
sudo apt-get install iptables
- Allow incoming UDP traffic on port 1194:
sudo iptables -A INPUT -p udp --dport 1194 -j ACCEPT
- Allow outgoing UDP traffic on port 1194:
sudo iptables -A OUTPUT -p udp --sport 1194 -j ACCEPT
- Save the
iptables
rules:
sudo sh -c "iptables-save > /etc/iptables/rules.v4"
Using ufw
- Install
ufw
(if not already installed):
sudo apt-get update
sudo apt-get install ufw
- Enable
ufw
:
sudo ufw enable
- Allow incoming UDP traffic on port 1194:
sudo ufw allow 1194/udp
- Allow outgoing UDP traffic on port 1194 (optional, usually
ufw
handles this automatically):
sudo ufw allow out 1194/udp
- Check
ufw
status to ensure the rule is added:
sudo ufw status
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
- For
ufw
:
sudo ufw status verbose
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;
}
E:\Projects\VS_Projects\UDPSender\Debug\UDPSender.exe 47.93.27.106 1194 “Hello. This is a test message for UDP 1194.”