Linux uses wget command to download network resources

Most of the Linux environments I contacted before were intranets. Generally, the traditional FTP server was used to store common resources. Some people directly downloaded from FTP when needed. If the company ’s FTP did not have the desired resources, it also needed to contact management and maintenance personnel to download and upload the corresponding medium.
At present, with the popularization of cloud ECS, many environments have the conditions to connect directly to the external network. We can use the wget command to download the required resources directly from the network.
For example, you can download the redis-3.2.10.tar.gz media directly with the following command:

wget http://download.redis.io/releases/redis-3.2.10.tar.gz

When I use wget download in the test environment, I get an error and cannot resolve the host address:

[root@test01 ~]# wget http://download.redis.io/releases/redis-3.2.10.tar.gz
--2020-04-22 22:13:29--  http://download.redis.io/releases/redis-3.2.10.tar.gz
Resolving download.redis.io... failed: Temporary failure in name resolution.
wget: unable to resolve host address “download.redis.io”

Try to ping www.baidu.com to prompt unknown host, ping 114.114.114.114 can succeed:

[root@test01 ~]# ping www.baidu.com
ping: unknown host www.baidu.com

[root@test01 ~]# ping 114.114.114.114
PING 114.114.114.114 (114.114.114.114) 56(84) bytes of data.
64 bytes from 114.114.114.114: icmp_seq=1 ttl=72 time=13.5 ms
64 bytes from 114.114.114.114: icmp_seq=2 ttl=90 time=10.2 ms

Obviously it is the problem of domain name resolution. Check /etc/resolv.conf and configure the correct nameserver:

[root@test01 ~]# vi /etc/resolv.conf 
nameserver 114.114.114.114

Try to ping www.baidu.com again successfully:

[root@test01 ~]# ping www.baidu.com
PING www.a.shifen.com (61.135.169.121) 56(84) bytes of data.
64 bytes from 61.135.169.121: icmp_seq=1 ttl=58 time=3.65 ms

Try wget again to download redis-3.2.10.tar.gz successfully:

[root@test01 ~]# wget http://download.redis.io/releases/redis-3.2.10.tar.gz
--2020-04-22 22:16:59--  http://download.redis.io/releases/redis-3.2.10.tar.gz
Resolving download.redis.io... 109.74.203.151
Connecting to download.redis.io|109.74.203.151|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1550261 (1.5M) [application/x-gzip]
Saving to: “redis-3.2.10.tar.gz”

100%[========================================================================================================================================>] 1,550,261    471K/s   in 3.2s    

2020-04-22 22:17:07 (471 KB/s) - “redis-3.2.10.tar.gz” saved [1550261/1550261]

View the downloaded file:

[root@test01 ~]# ls -lrth redis-3.2.10.tar.gz 
-rw-r--r--. 1 root root 1.5M Jul 29  2017 redis-3.2.10.tar.gz

It can be seen that in a Linux environment that can connect to the external network, as long as the domain name resolution server is correctly configured, it is very convenient to use wget to directly download the required resources.
If the downloaded resources are large, you can also download in the nohup wget xxxx &background in a coordinated manner.

Guess you like

Origin www.cnblogs.com/jyzhao/p/12757477.html