This website uses my personal domain name. Here is how the domain name was purchased and the configurations of the domain name, including setting up a dynamically domain name system (DDNS).
Motivation
I need to use ssh
to login to the computers in my home and office frequently for some working reasons. However, there’s no fixed IP addresses for those computers. After the IP addresses changed, I lost the connection to the computers and could not re-connect immediately (because I don’t know the new IP address).
So I was considering to use domain name instead of IP address for connecting those computers. Then I looked at the prices of the domain names, finding that there’re some cheap ones (Although the domain names with .com are usually very expensive, the ones with .xyz, .top, .cyou, etc are much cheaper).
Purchase Domain Name from Alibaba Cloud
-
Register an account for Alibaba Cloud
Go to Alibaba Cloud International Website, and register an international account (no need for real-name authentication!)。 -
Look up and purchase a domain name
-
Go to Alibaba International Domain Name Market, and search for the secondary domain name you want, for example, I searched for “jinli”.
-
The result page will show all domain names that are available:
-
Purchase the domain name you need with the Alibaba account you registered in the last step. For example, I purchased “jinli.cyou”.
-
Resolving Domain Name to Server’s IP Address (DNS)
- The domain name your purchased needs to be resolved to your server’s IP address before you can use domain name to visit your computer.
- If you have a fixed IP address for your server (computer), you can assign the IP address to your domain name on Alibaba Cloud.
- If you don’t have a fixed IP address for your server (computer), you need to dynamically resolve the domain name to your server’s IP address.
Having a fixed IP address – assign it to your domain name directly
-
Obtain your IP address
-
Go to IPv6 Testing to check whether your network supports IPv6:
-
On a Unix-like OS, you can use following command to get your IPv4 address:
1
curl ipinfo.io/ip
and use following command for IPv6 address:
1
curl ipv6.icanhazip.com
-
-
Assign your domain name with your IP address
- Login to International Alibaba Cloud, click on the user’s avatar and select “Account Management” in the menu.
- Moving the mouse cursor to the upper left menu, you will see a drop-down menu. Click “Domains”.
- Click on the domain name you purchased in the domain name list.
- Click on the “DNS Settings” in the right-side menu.
- Click on “Add Record” to assign an IP address to your domain name:
- Type:For IPv4 address, choose “A”; for IPv6 address, choose “AAAA”.
- Host:Enter the third-level domain name you need. For example, if you need to set up an IP address for “surface.jinli.cyou”, you need to enter “surface”. For more instructions about the domain name settings, you can click on the question mark for details.
- ISP Line:Choose “default”.
- Value:Enter the IP address your obtained from the last step. (IPv4 address for “A” and IPv6 address for “AAAA”)
- TTL:Time interval for IP address updating, 10 minutes in the default is fine.
- You can add multiple domain name - IP address pairs, for both IPv4 and IPv6 addresses.
-
Check After adding the record, you may need to wait for 10 minutes for Alibaba Cloud to update the info in their DNS server (usually it will be updated once you submitted the record). Then you can check whether the record is added successfully.
- Use
ping
command to check it in another network environmentIf the1
ping surface.jinli.cyou
ping
is successful in a public network environment, it means you got the domain name bounded with your IP address successfully.
- Use
-
Done! After binding your domain name with your IP address, you can login to your server with the domain name. For example, if you need to use
ssh
to login to your remote server, you canssh
via domain name:1
ssh [email protected] -X
You can also build a NAS (Network Attached Stordage), etc on your server, and visit it via domain name.
Don’t have a fixed IP address —— Add record and dynamically DNS resolving (DDNS)
If your computer or server don’t have a fixed IP address, you need to add a record using your current IP address on Alibaba Cloud following the instructions above. Then you need to watch the IP address on your computer, once it changes, the record on Alibaba Cloud DNS server can be updated using the API provided by Alibaba Cloud. Basically, here are what we are doing:
- Use a Python3 script to do dynamical DNS (DDNS)
- The Python3 script uses Alibaba Cloud API
- It needs the Access key generated by your Alibaba Cloud account for password-free login
- For the security of your account, Do NOT leak your Access key. Once it leaks, login to your Alibaba Cloud account and delete the Access key immediately.
- Download the DDNS script
- The DDNS(Dynamic Domain Name System) script was adapted from the aliyun-ddns-client repo on GitHub. There’re two problems to use it directly in USA:
- The website for obtaining IP address is unavailable in USA
- Some problem for IPv6 address support
- So I forked this repo and fixed above problems. My repo is on https://github.com/jin-li/aliyun-ddns-client
- The DDNS script uses Python3
- Use following command to clone the repo. Placing it in
~/.config
folder is recommended (If there’s no.config
folder inhome
directory, you should create the directory dirst):1 2
cd ~/.config git clone https://github.com/jin-li/aliyun-ddns-client
- Install the dependency Python package
requests
andnetifaces
- The DDNS(Dynamic Domain Name System) script was adapted from the aliyun-ddns-client repo on GitHub. There’re two problems to use it directly in USA:
- Generate Access key in your Alibaba Cloud
- Login to your Alibaba Cloud account, click on the menu at the upper left corner and find Resource Access Management in Management and Governance:
- After entering the RAM page, click on the Users in Identities in the left side menu. Then click on Create User to create a new user. Enter “Logon Name” and “Display Name”, check the “API Call-based Access” so that you can login to the account via API:
- After creating a new user, return the “RAM/Users” page. Click on the user name you created, and enter “User” setting page. Go to the bottom of the page, click on the Create AccessKey Pair button in User AccessKeys to generate an AccessKey. Write down the “Access ID” and “Access Key” poped out. Note that the Access Key appears only once. Once you close the poped-out page, it will disappear. But you can re-create one.
- Configure and run the script
- Go to the directory where you placed the
aliyun-ddns-client
repo. Finding the fileddns.conf.example
, rename it asddns-conf
. - Open
ddns.conf
with a text editor. Fill in the “Access ID” and “Access Key” you obtained from the last step. Then fill in your domain name and the corresponding IP address (The correctness of the IP address doesn’t matter since if it’s wrong, the script will correct it during running. But the domain name must be correct). - If you have multiple domain names for resolving, you can add more entries
ddns.conf
imitating the existing examples. It supports both IPv4 and IPv6 addresses. Note that the domain name must be those were already created on Alibaba Cloud . - Then you can run the script using Python3:
1
python3 ddns.py
- The script will check whether the current IP address matches what is on the Alibaba Cloud DNS server on each of its running. If it is not the same as on the Alibaba Cloud DNS server, it will update the record on the server.
- Go to the directory where you placed the
- Setup a regular timed task for DDNS
- If your computer or server don’t have a fixed IP address, the IP address will change after some time. You need to update the record on Alibaba Cloud DNS server as soon as possible.
- To watch the IP address change manually is not convenient, you can setup a timed task and let the OS run the DDNS script in a certain time interval (for example, every hour). Then you can assure that the record can be updated in one hour after the IP address changes.
- In a Unix-like OS, the timed task can be setup using a system tool called
crontab
. You can find some instructions for how to setupcrontab
at https://crontab.guru/#. - For example, if you want the DDNS script to run at the 42th minute every hour, you can use following command:
which will open a configuration file containing
1
crontab -e
crontab
timed tasks, you can append one following line at the end of the file:1
42 * * * * cd ~/.config/aliyun-ddns-client ipython3 ddns.py
- Then you can use following command to check whether the timed task is running:
1
crontab -l