how to extract just the IP address from a DNS query
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I'd like to know how to extract just the IP address from a DNS / dig query. The query I'm running looks like this:
lab-1:/var/# dig +answer smtp.mydomain.net +short
smtp.ggs.mydomain.net
10.11.11.11
I'd like to be able to get just the IP address returned.
I'm currently playing around with the bash pipe and the awk command. But so far, nothing I've tried is working.
Thanks.
bash dns dig
 |Â
show 1 more comment
up vote
0
down vote
favorite
I'd like to know how to extract just the IP address from a DNS / dig query. The query I'm running looks like this:
lab-1:/var/# dig +answer smtp.mydomain.net +short
smtp.ggs.mydomain.net
10.11.11.11
I'd like to be able to get just the IP address returned.
I'm currently playing around with the bash pipe and the awk command. But so far, nothing I've tried is working.
Thanks.
bash dns dig
4
drop+answer
use just+short
â man0v
Feb 26 at 14:16
that doesn't work. still gives me the same results @man0v
â dot
Feb 26 at 14:18
weird, it works for me oncentos
.. wonder what version ofdig
you are using? What distro(or os)?
â man0v
Feb 26 at 14:19
1
@dot post dig version too. Usedig -v
â Patrick
Feb 26 at 14:26
1
Is smtp.mydomain.net an alias for smtp.ggs.mydomain.net?
â ctx
Feb 26 at 14:31
 |Â
show 1 more comment
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'd like to know how to extract just the IP address from a DNS / dig query. The query I'm running looks like this:
lab-1:/var/# dig +answer smtp.mydomain.net +short
smtp.ggs.mydomain.net
10.11.11.11
I'd like to be able to get just the IP address returned.
I'm currently playing around with the bash pipe and the awk command. But so far, nothing I've tried is working.
Thanks.
bash dns dig
I'd like to know how to extract just the IP address from a DNS / dig query. The query I'm running looks like this:
lab-1:/var/# dig +answer smtp.mydomain.net +short
smtp.ggs.mydomain.net
10.11.11.11
I'd like to be able to get just the IP address returned.
I'm currently playing around with the bash pipe and the awk command. But so far, nothing I've tried is working.
Thanks.
bash dns dig
asked Feb 26 at 14:14
dot
2531310
2531310
4
drop+answer
use just+short
â man0v
Feb 26 at 14:16
that doesn't work. still gives me the same results @man0v
â dot
Feb 26 at 14:18
weird, it works for me oncentos
.. wonder what version ofdig
you are using? What distro(or os)?
â man0v
Feb 26 at 14:19
1
@dot post dig version too. Usedig -v
â Patrick
Feb 26 at 14:26
1
Is smtp.mydomain.net an alias for smtp.ggs.mydomain.net?
â ctx
Feb 26 at 14:31
 |Â
show 1 more comment
4
drop+answer
use just+short
â man0v
Feb 26 at 14:16
that doesn't work. still gives me the same results @man0v
â dot
Feb 26 at 14:18
weird, it works for me oncentos
.. wonder what version ofdig
you are using? What distro(or os)?
â man0v
Feb 26 at 14:19
1
@dot post dig version too. Usedig -v
â Patrick
Feb 26 at 14:26
1
Is smtp.mydomain.net an alias for smtp.ggs.mydomain.net?
â ctx
Feb 26 at 14:31
4
4
drop
+answer
use just +short
â man0v
Feb 26 at 14:16
drop
+answer
use just +short
â man0v
Feb 26 at 14:16
that doesn't work. still gives me the same results @man0v
â dot
Feb 26 at 14:18
that doesn't work. still gives me the same results @man0v
â dot
Feb 26 at 14:18
weird, it works for me on
centos
.. wonder what version of dig
you are using? What distro(or os)?â man0v
Feb 26 at 14:19
weird, it works for me on
centos
.. wonder what version of dig
you are using? What distro(or os)?â man0v
Feb 26 at 14:19
1
1
@dot post dig version too. Use
dig -v
â Patrick
Feb 26 at 14:26
@dot post dig version too. Use
dig -v
â Patrick
Feb 26 at 14:26
1
1
Is smtp.mydomain.net an alias for smtp.ggs.mydomain.net?
â ctx
Feb 26 at 14:31
Is smtp.mydomain.net an alias for smtp.ggs.mydomain.net?
â ctx
Feb 26 at 14:31
 |Â
show 1 more comment
2 Answers
2
active
oldest
votes
up vote
1
down vote
accepted
I believe dig +short
outputs two lines for you because the domain
you query, smtp.mydomain.net
is a CNAME for smtp.ggs.mydomain.net
,
and dig prints the intermediate resolution step.
You can probably rely on the last line from dig's output being the IP
you want, though, and therefore the following should do:
dig +short smtp.mydomain.net | tail -n1
add a comment |Â
up vote
1
down vote
@dhag's answer sounds good; if you do not want to âÂÂrely on the last line from dig's output being the IPâ you can use grep
to extract just the numerical IP address:
dig +short smtp.mydomain.net | grep '^[.0-9]*$'
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
I believe dig +short
outputs two lines for you because the domain
you query, smtp.mydomain.net
is a CNAME for smtp.ggs.mydomain.net
,
and dig prints the intermediate resolution step.
You can probably rely on the last line from dig's output being the IP
you want, though, and therefore the following should do:
dig +short smtp.mydomain.net | tail -n1
add a comment |Â
up vote
1
down vote
accepted
I believe dig +short
outputs two lines for you because the domain
you query, smtp.mydomain.net
is a CNAME for smtp.ggs.mydomain.net
,
and dig prints the intermediate resolution step.
You can probably rely on the last line from dig's output being the IP
you want, though, and therefore the following should do:
dig +short smtp.mydomain.net | tail -n1
add a comment |Â
up vote
1
down vote
accepted
up vote
1
down vote
accepted
I believe dig +short
outputs two lines for you because the domain
you query, smtp.mydomain.net
is a CNAME for smtp.ggs.mydomain.net
,
and dig prints the intermediate resolution step.
You can probably rely on the last line from dig's output being the IP
you want, though, and therefore the following should do:
dig +short smtp.mydomain.net | tail -n1
I believe dig +short
outputs two lines for you because the domain
you query, smtp.mydomain.net
is a CNAME for smtp.ggs.mydomain.net
,
and dig prints the intermediate resolution step.
You can probably rely on the last line from dig's output being the IP
you want, though, and therefore the following should do:
dig +short smtp.mydomain.net | tail -n1
answered Feb 26 at 14:38
dhag
10.7k32642
10.7k32642
add a comment |Â
add a comment |Â
up vote
1
down vote
@dhag's answer sounds good; if you do not want to âÂÂrely on the last line from dig's output being the IPâ you can use grep
to extract just the numerical IP address:
dig +short smtp.mydomain.net | grep '^[.0-9]*$'
add a comment |Â
up vote
1
down vote
@dhag's answer sounds good; if you do not want to âÂÂrely on the last line from dig's output being the IPâ you can use grep
to extract just the numerical IP address:
dig +short smtp.mydomain.net | grep '^[.0-9]*$'
add a comment |Â
up vote
1
down vote
up vote
1
down vote
@dhag's answer sounds good; if you do not want to âÂÂrely on the last line from dig's output being the IPâ you can use grep
to extract just the numerical IP address:
dig +short smtp.mydomain.net | grep '^[.0-9]*$'
@dhag's answer sounds good; if you do not want to âÂÂrely on the last line from dig's output being the IPâ you can use grep
to extract just the numerical IP address:
dig +short smtp.mydomain.net | grep '^[.0-9]*$'
answered Feb 26 at 16:16
Renardo
862
862
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f426693%2fhow-to-extract-just-the-ip-address-from-a-dns-query%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
4
drop
+answer
use just+short
â man0v
Feb 26 at 14:16
that doesn't work. still gives me the same results @man0v
â dot
Feb 26 at 14:18
weird, it works for me on
centos
.. wonder what version ofdig
you are using? What distro(or os)?â man0v
Feb 26 at 14:19
1
@dot post dig version too. Use
dig -v
â Patrick
Feb 26 at 14:26
1
Is smtp.mydomain.net an alias for smtp.ggs.mydomain.net?
â ctx
Feb 26 at 14:31