LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 01-19-2015, 10:13 AM   #1
abefroman
Senior Member
 
Registered: Feb 2004
Location: lost+found
Distribution: CentOS
Posts: 1,430

Rep: Reputation: 55
What is the best way to find the IP of a domain's primary mail server?


What is the best way to find the IP of a domain's primary mail server?

This command works, but seems a little over complicated:
Code:
host `host -tmx domain.com | awk {'print $6 " " $7'} |sort -n | awk {'print $2'}` |grep address |awk {'print $4'}
 
Old 01-19-2015, 10:55 AM   #2
AlucardZero
Senior Member
 
Registered: May 2006
Location: USA
Distribution: Debian
Posts: 4,824

Rep: Reputation: 615Reputation: 615Reputation: 615Reputation: 615Reputation: 615Reputation: 615
Not much better:

Code:
dig +short -x PTR $(dig +short MX domain.com | sort -n | head -n1 | awk '{print $2}')
Don't forget that there can be multiple MX records, so I added the 'head -n1'

Last edited by AlucardZero; 01-19-2015 at 10:56 AM.
 
1 members found this post helpful.
Old 01-19-2015, 11:37 AM   #3
dijetlo
Senior Member
 
Registered: Jan 2009
Location: RHELtopia....
Distribution: Solaris 11.2/Slackware/RHEL/
Posts: 1,491
Blog Entries: 2

Rep: Reputation: Disabled
I tried this Al, with varying results. It's important to remember you're not actually targeting a mail servers with DNS. More often, the MX and PTR records are directed at a load balancer that shuffles the requests across multiple IPs as part of an SMTP-DOS defense strategy. In effect, you are looking for the Domain IP address that accepts mail for forwarding and there are any number of those and none of the "primary".
Still, great script, it expanded my thinking as far as substitution.

Last edited by dijetlo; 01-19-2015 at 11:38 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
"the trust relation between this workstation and the primary domain failed" windows 7 domain joining ach68 Linux - Server 2 03-27-2011 11:33 PM
Domain for a mail server Mr. Alex Linux - Server 1 11-10-2010 06:11 AM
Mail to subdomain need to be redirected to mail server in another domain Tafta Linux - Networking 2 06-08-2009 09:42 PM
mail server - no domain name jaymare Debian 2 04-02-2006 06:40 AM
Mail server without domain learn25 Red Hat 0 02-25-2004 03:52 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 03:49 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration