I have one Google Compute Engine instance and I want to open udp port 53 on it. I have added some firewall rules(as in this link) to allow traffic, but it does not seem to solve the problem. (Only worked when I tried to open TCP port 8080 for a web server)
VPC firewall rules
I have also tried updating the iptable rules manually:
sudo iptables -A INPUT -p udp -m udp --dport 53 -j ACCEPT && sudo iptables -A INPUT -m state --state NEW -p tcp --dport 8080 -j ACCEPT && sudo netfilter-persistent save
The DNS server I would like to open on port 53 on the VM:
from scapy.layers.dns import DNS, DNSRR
import socket
simple_udp = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, proto=socket.IPPROTO_UDP)
simple_udp.bind(('0.0.0.0', 53))
domains = {
b"proiect-retele-reguli-stricte.chickenkiller.com.": "34.118.118.214",
}
print(domains.keys())
try:
while True:
request, adresa_sursa = simple_udp.recvfrom(65535)
# converitm payload-ul in pachet scapy
packet = DNS(request)
dns = packet.getlayer(DNS)
if dns is not None and dns.opcode == 0: # dns QUERY
print ("got: ")
print (packet.summary())
print(dns.qd.qname)
if dns.qd.qname in domains.keys():
dns_answer = DNSRR( # DNS Reply
rrname=dns.qd.qname, # for question
ttl=330, # DNS entry Time to Live
type="A",
rclass="IN",
rdata=domains[dns.qd.qname])
dns_response = DNS(
id = packet[DNS].id, # DNS replies must have the same ID as requests
qr = 1, # 1 for response, 0 for query
aa = 0, # Authoritative Answer
rcode = 0,
qd = packet.qd,
an = dns_answer)
print('response:')
print (dns_response.summary())
simple_udp.sendto(bytes(dns_response), adresa_sursa)
except KeyboardInterrupt:
simple_udp.close()
Every time I am running this on my local machine I always get “No response received”
from scapy.all import *
def dns_query(target_ip, dns_server):
dns_query = IP(dst=dns_server)/UDP(dport=53)/DNS(rd=1, qd=DNSQR(qname=target_ip))
responses, _ = sr(dns_query, verbose=0, retry=2, timeout=5)
if responses:
for pkt in responses:
if pkt[DNS].an:
print(pkt.summary())
else:
print("No response received.")
else:
print("No response received.")
dns_query("proiect-retele--stricte.chickenkiller.com.", "34.118.23.175") # vm external ip
Is there anything that is blocking traffic on udp:53 or am doing something incorrectly?
marius004 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.