Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to rewrite ptr records #2

Open
sxauyhz opened this issue Oct 15, 2019 · 7 comments
Open

how to rewrite ptr records #2

sxauyhz opened this issue Oct 15, 2019 · 7 comments

Comments

@sxauyhz
Copy link

sxauyhz commented Oct 15, 2019

for example, corefile :

rewriteng ANY ANY substring k8s.test.com  nginx-deploy.default.svc.cluster.local {
          answer name regex (.*)\.nginx-deploy.default.svc.cluster.local. {1}.k8s.test.com.
          answer data regex (.*)\.nginx-deploy.default.svc.cluster.local. {1}.k8s.test.com.
          authority both suffix nginx-deploy.default.svc.cluster.local. k8s.test.com.
          additional both suffix nginx-deploy.default.svc.cluster.local. k8s.test.com.
}

~]# nslookup nginx-rc1-77bpb.k8s 127.0.0.1
Server: 127.0.0.1
Address: 127.0.0.1#53

Name: nginx-rc1-77bpb.k8s.test.com
Address: 10.30.253.110

~]# nslookup 10.30.253.110 127.0.0.1
Server: 127.0.0.1
Address: 127.0.0.1#53

110.253.30.10.in-addr.arpa name = nginx-rc1-77bpb.nginx-deploy.default.svc.cluster.local.

### how to rewrite "nginx-rc1-77bpb.nginx-deploy.default.svc.cluster.local." to "nginx-rc1-77bpb.k8s.test.com" ??

@akissa
Copy link
Owner

akissa commented Oct 15, 2019

The data rule should rewrite it, what do the logs state ?

@sxauyhz
Copy link
Author

sxauyhz commented Oct 16, 2019

;; flags: qr aa rd; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

Here is "nslookup nginx-rc1-77bpb.k8s.test.com" 127.0.0.1 logs :

;; QUESTION SECTION:
;nginx-rc1-77bpb.k8s.test.com.  IN       A

;; ANSWER SECTION:
nginx-rc1-77bpb.nginx-deploy.default.svc.cluster.local. 5       IN      A       10.30.253.110
2019-10-16T10:24:04.355+08:00 [INFO] plugin/rewriteng: calling rewriteAnswers -> rewriteDataParts for rr nginx-rc1-77bpb.k8s.test.com.  5       IN      A       10.30.253.110 rule &{substring 0xc0003f6b70 255 255 [0xc0003f6c00 0xc0003f6c90] [] []} answerRule answer

and here is "nslookup 10.30.253.110 127.0.0.1" logs:

2019-10-16T10:24:18.501+08:00 [INFO] plugin/rewriteng: plug-in calls RewriteNG
2019-10-16T10:24:18.501+08:00 [INFO] plugin/rewriteng: plug-in calls RewriteNG

@akissa
How to modify the configuration make 'nslookup 10.30.253.110 127.0.0.1' respone 'nginx-rc1-77bpb.nginx-deploy.default.svc.cluster.local. ' rewrite to 'nslookup nginx-rc1-77bpb.k8s.test.com'

@akissa
Copy link
Owner

akissa commented Oct 16, 2019

You should be looking up PTR 110.253.30.10.in-addr.arpa.

@akissa
Copy link
Owner

akissa commented Oct 16, 2019

dig @127.0.0.1 PTR 110.253.30.10.in-addr.arpa.

@sxauyhz
Copy link
Author

sxauyhz commented Oct 16, 2019

dig @127.0.0.1 PTR 110.253.30.10.in-addr.arpa. Can not rewrie to 'nginx-rc1-77bpb.k8s.test.com', still is "nginx-rc1-77bpb.nginx-deploy.default.svc.cluster.local."
my cfg is:

rewriteng ANY ANY substring k8s.test.com  nginx-deploy.default.svc.cluster.local {
          answer name regex (.*)\.nginx-deploy.default.svc.cluster.local.$ {1}.k8s.test.com.
          answer data regex (.*)\.nginx-deploy.default.svc.cluster.local. {1}.k8s.test.com.
}

]# dig @127.0.0.1 PTR 110.253.30.10.in-addr.arpa.

; <<>> DiG 9.9.4-RedHat-9.9.4-38.el7_3.3 <<>> @127.0.0.1 PTR 110.253.30.10.in-addr.arpa.
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 640
;; flags: qr aa rd; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; WARNING: recursion requested but not available

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;110.253.30.10.in-addr.arpa. IN PTR

;; ANSWER SECTION:
110.253.30.10.in-addr.arpa. 5 IN PTR nginx-rc1-77bpb.nginx-deploy.default.svc.cluster.local.

;; Query time: 0 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Wed Oct 16 14:18:39 CST 2019
;; MSG SIZE rcvd: 149

@akissa
Copy link
Owner

akissa commented Oct 16, 2019

On a side note your regex is incorrect, you need to escape all the dots. What does the log show ?

@sxauyhz
Copy link
Author

sxauyhz commented Oct 16, 2019

@akissa @kapilth
when escape all the dots, as follows:

rewriteng ANY ANY substring k8s.test.com  nginx-deploy.default.svc.cluster.local {
          answer name regex (.*)\.nginx-deploy\.default\.svc\.cluster\.local\.$ {1}.k8s.test.com.
          answer data regex (.*)\.nginx-deploy\.default\.svc\.cluster\.local\.$ {1}.k8s.test.com.
}

then test nslooup:

]# nslookup  nginx-rc1-77bpb.k8s.test.com 127.0.0.1
Server:		127.0.0.1
Address:	127.0.0.1#53

Name:	nginx-rc1-77bpb.k8s.test.com
Address: 10.30.253.110

]# nslookup 10.30.253.110 127.0.0.1
Server:		127.0.0.1
Address:	127.0.0.1#53

110.253.30.10.in-addr.arpa	name = nginx-rc1-77bpb.nginx-deploy.default.svc.cluster.local.

Looks like no change!!!
The logs as follows:

 ]# /usr/bin/coredns-v1.5.0 -conf /etc/coredns/Corefile
.:53
2019-10-16T14:59:02.763+08:00 [INFO] CoreDNS-1.5.0
2019-10-16T14:59:02.763+08:00 [INFO] linux/amd64, go1.13.1, e3f9a80-dirty
CoreDNS-1.5.0
linux/amd64, go1.13.1, e3f9a80-dirty

2019-10-16T14:59:05.636+08:00 [INFO] plugin/rewriteng: plug-in calls RewriteNG
2019-10-16T14:59:05.636+08:00 [INFO] plugin/rewriteng: plug-in calls RewriteNG
2019-10-16T14:59:05.636+08:00 [INFO] plugin/rewriteng: Calling next plugin: rewriteng
2019-10-16T14:59:05.636+08:00 [INFO] plugin/rewriteng: In ResponseWriter ;; opcode: QUERY, status: NOERROR, id: 40291
;; flags: qr aa rd; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;nginx-rc1-77bpb.k8s.test.com.  IN       A

;; ANSWER SECTION:
nginx-rc1-77bpb.nginx-deploy.default.svc.cluster.local. 5       IN      A       10.30.253.110
2019-10-16T14:59:05.636+08:00 [INFO] plugin/rewriteng: calling rewriteAnswers -> rewriteDataParts for rr nginx-rc1-77bpb.k8s.test.com.  5       IN      A       10.30.253.110 rule &{substring 0xc000414360 255 255 [0xc0004143f0 0xc000414480] [] []} answerRule answer
2019-10-16T14:59:12.925+08:00 [INFO] plugin/rewriteng: plug-in calls RewriteNG
2019-10-16T14:59:12.925+08:00 [INFO] plugin/rewriteng: plug-in calls RewriteNG

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants