In Linux, dynamic IP addresses are automatically directed to domain names.

Source: Internet
Author: User
Tags to domain fully qualified domain name
Article Title: in Linux, dynamic IP addresses are automatically directed to domain names. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
On the Internet, users' domain names and IP addresses correspond one by one. However, a dynamic IP address is generated when you access the Internet through virtual dialing. This is troublesome for computer enthusiasts who do not have much money to apply for a domain name. A few days ago, I had a lot of trouble because I changed my region's ADSL to the virtual dialing method. After many debugging, I finally realized the dynamic IP address in Linux? Br> scratch? Far? Why? Why is it true? Krypton night silkworms?
  
Previously. However, when ADSL is changed to the virtual dialing method, there is no fixed IP address. It is very troublesome to start dns2go. first use the ifconfig command to find the IP address obtained by ppp0, and then in/etc/dns2go. to start dns2go. Manual operations are required for each start, which is inconvenient. It cannot be started automatically without human intervention. I wrote a C program to solve the problem. In this example, all the programs are assumed to be installed in the/usr/local/bin/Program (intermediate file), dns2go. conf (typical configuration file? Br>?
  
The xnbh shell program is as follows:
Adsl-start # start the virtual dialing program of adls, ifconfig ppp0 | grep-v "Link">/usr/local/bin/pppoe.txt.pdf in the directory, extract the IP value in the pppoe.txt file/usr/local/bin/Transcoder and replace dns2go. generate the intermediate file outfilecp/etc/dns2go. conf/etc/dns2go. confold # back up the original dns2go. conf file cp/usr/local/bin/outfile/etc/dns2go. conf # dns2go after replacement. conf file nohup/usr/local/bin/dns2go>/var/tmp/dns2go. log 2> & 1 & # Start a fixed domain name
  
The pppoe.txt after executing the second sentence in xnbhis is as follows:
Inet addr: 218.65.217.109 P-t-P: 172.0.0.1 Mask: 255.255.255.255
Up pointopoint running noarp multicast mtu: 1492 Metric: 1
RX packets: 26 errors: 0 dropped: 0 overruns: 0 frame: 0
TX packets: 27 errors: 0 dropped: 0 overruns: 0 carrier: 0
Collisions: 0 txqueuelen: 3
RX bytes: 1400 (1.3 Kb) TX bytes: 1358 (1.3 Kb)
  
The original program of trans. c is as follows:
# Include
# Include
Main ()
{
FILE * fp, * bp, * out;
Int I = 0;
Int j;
Char ip [16];
Char dip [16];
Char na [] = "address = ";
Char inip [24];
Char readln [255];
Char readlnn [255];
Fp = fopen ("/usr/local/bin/pppoe.txt", "r ");
If (fgets (readln, 255, fp )! = NULL)
{For (I = 0; I <16; I ++) ip = readln [20 + I];
  
}
I = 0;
For (I = 0; I <16; I ++)
{If (ip! = '')
{Dip = ip; printf ("ip % d = % c \ n", I, ip );}
Else {j = I; printf ("j = % d", j );}}
For (I = 0; I <= j; I ++) dip = ip;
Dip [j] = '\ 0 ';
Printf ("a = % s \ n", dip );
Fclose (fp );
Strcpy (inip, na );
Printf ("inip = % s \ n", inip );
Strcat (inip, dip );
  
Printf ("inip = % s \ n", inip );
Fp = fopen ("/usr/local/bin/dns2go. conf", "r ");
Out = fopen ("/usr/local/outfile", "w ");
While (! Feof (fp )){
If (fgets (readlnn, 255, fp )! = NULL)
If (strncmp ("address = aaa. bbb. ccc. ddd", readlnn, 15) fputs (readlnn, out );
Else fputs (inip, out );}
Fclose (fp );
Fclose (out );
  
}
  
Using gcc in linux? O trans. c compiled by generating the file trans,
  
The configuration of dns2go. conf is as follows:
#
# Simple configuration file for DNS2Go linux client
#
# For more information refer to the dns2go. conf manual page
  
#
# GLOBAL ctictives
#
# DNS2Go Server
Server = discovery.dns2go.com
  
# Key (required, case-sensitive)
Key = aaaaaa-bbbbbb-ccccccc-ddddd (this is the activation code applied)
  
# Log file (optional, default: syslog)
# Log =/var/log/dns2go.txt
  
# Send debug output to stdout
Debug
  
# Number of connection attempts (optional, default: 8)
# Retries = 8
  
# Rate to send heartbeats (in minutes) (optional, default: 0 = automatic)
# Heartbeat-rate = 0
  
#
# DOMAIN DIRECTIVES
#
# Fully qualified domain name (required)
Domain = XXXXX.dnsgo.com (enter a fixed free domain Name)
  
# Static IP address (optional, default: external IP address)
Address = aaa. bbb. ccc. ddd (assuming IP)
  
# Online www alias redirection: choose one of the following:
# (Optional, default: www alias resolves to domain IP)
# Www-redirect-url = http ://...
# Www.redirect-port = 8080
  
# Offline redirect option: choose one of the following
# (Optional, default: offline status page)
# Offline-url = http ://...
# Offline-ip = 0.0.0.0
  
If the above xnbh program is added to/etc/rc. d/rc. in local/, the fixed free domain name can be automatically started at startup. You can use this free domain name for apache, ftp, and telnet, when you leave, you can easily find your own server. If you are familiar with shell, you can also use shell to complete the C program function. The above program passes through redhat7.2 smoothly.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.