How to find DNS servers for each PPP session in linux?

5,083

man pppd:

   usepeerdns
         Ask the peer for up to 2 DNS server addresses.  The addresses supplied 
         by the peer (if any) are passed to the /etc/ppp/ip-up script in the  
         environment  variables  DNS1  and DNS2, and the environment variable 
         USEPEERDNS will be set to 1.  In addition, pppd will create an /etc/ppp/
         resolv.conf file containing one or two nameserver lines with the
         address(es) supplied by the peer.

So just evaluate DNS1 and DNS2 in your ip-up script (which is run once after the PPP connection is established) and if you need this information later on, store it somewhere.

But as mailq has written, there is really only little use for this kind of feature.

Share:
5,083

Related videos on Youtube

Ravi
Author by

Ravi

Updated on September 18, 2022

Comments

  • Ravi
    Ravi almost 2 years

    How to get the DNS server address which are specific to each ppp session. For example, I have two ppp sessions each one connected different service provider, how do I find out the DNS server IP address which are assigned by each service provider? In general, the /etc/ppp/resolv.conf file will be overwritten with the new DNS IP address whenever a new ppp session is established. Is there any way how we can maintain separate files for DNS servers for each service provider?

    • mailq
      mailq over 12 years
      WHy would you? Each DNS is similar so why not choose any of them. It doesn't matter which one you use.
    • Ravi
      Ravi over 12 years
      I have the requirement to maintains the DNS server ip addresses for each service provider.
    • kasperd
      kasperd over 5 years
      @mailq There are multiple reasons why they might return different results. For example it is not uncommon for content distribution networks to tailor DNS responses to each ISP. Moreover it is possible that one or both ISPs may be using NAT64 in which case they will return different responses.