解决wget访问外网问题:步骤一
解决apt访问外网问题:步骤一到步骤六。其中步骤一(设置用户代理)、步骤二(添加证书)、步骤四(修改DNS等网络参数配置)、步骤六(修改apt全局配置)为关键步骤。供参考。我是从步骤一尝试到步骤六,最后解决的。之后如果问题反复出现,还是可以尝试这几个关键步骤。
主要的报错可以参考后文。
一开始如果wget也不能联网,报错:
$ sudo wget www.baidu.com
--2020-04-01 15:23:01-- http://www.baidu.com/
Resolving www.baidu.com (www.baidu.com)... failed: No address associated with hostname.
wget: unable to resolve host address ‘www.baidu.com’
就通过步骤一解决。比较难以解决的是apt联网的问题。详见后文。
================================================================================
可以按照以下步骤依次尝试:
步骤一:在~/.bashrc中设置代理
$ sudo vi ~/.bashrc
在文件后面加入内容
http_proxy=http://10.xx.xx.xxx:8080
https_proxy=http://10.xx.xx.xxx:8080
$ source ~/.bashrc
如果报错
Proxy request sent, awaiting response... 200 OK
Length: 2250 (2.2K) [text/html]
index.html: Permission denied
Cannot write to ‘index.html’ (Success).
说明你对当前的文件夹没有写入权限,改一下权限就可以了
$ sudo chmod 777 -R temp
此时wget能用了。但是apt还是不能用
Something wicked happened resolving 'cn.archive.ubuntu.com:http' (-5 - No address associated with hostname)
E: Failed to fetch http://cn.archive.ubuntu.com/ubuntu/pool/universe/x/xorg/xbase-clients_7.7+13ubuntu3.1_all.deb Something wicked happened resolving 'cn.archive.ubuntu.com:http' (-5 - No address associated with hostname)
E: Failed to fetch http://cn.archive.ubuntu.com/ubuntu/pool/universe/v/vnc4/vnc4server_4.1.1+xorg4.3.0-37.3ubuntu2_amd64.deb Something wicked happened resolving 'cn.archive.ubuntu.com:http' (-5 - No address associated with hostname)
E: Failed to fetch http://security.ubuntu.com/ubuntu/pool/universe/x/xrdp/xrdp_0.6.1-2ubuntu0.3_amd64.deb Something wicked happened resolving 'cn.archive.ubuntu.com:http' (-5 - No address associated with hostname)
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?
如果还不行,就给wget创建专门的配置文件:
$ sudo vi ~/.wgetrc
加入
# u can set the default proxies for Wget to use for http, https, and ftp.
# They will override the value in the environment.
https_proxy=http://10.xx.xx.xxx:8080
http_proxy=http://10.xx.xx.xxx:8080
# If you do not want to use proxy at all, set this to off.
use_proxy=on
使用:
$ source ~/.wgetrc
这时候再试试:
$ wget www.baidu.com
参考:https://www.cnblogs.com/cloud2rain/archive/2013/03/22/2976337.html
步骤二:如果还是报错,添加证书:https://blog.csdn.net/qxqxqzzz/article/details/102461881
步骤三:如果还是报错,打开firefox浏览器, $sudo firefox
自动蹦出网关登录,蹦不出来你就手动输入地址打开以下吧,类似于这种东西:
http://10.xxx.xxx.xxx/ac_portal/default/pc.html?template=default&tabs=pwd&vlanid=0&url=http://www.baidu.com/
这里的10.xxx.xxx.xxx和步骤一中的10.xxx.xxx.xxx 相同。然后 输入公司内网域账号密码,登录网关。
如果apt还是不能联网。继续下一步。
步骤四:如果还是报错,修改
$ sudo vi /etc/network/interfaces
,内容为:
# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback
# primary network interface
auto eno2
iface eno2 inet static
address 10.167.xxx.xxx
netmask 255.255.xxx.xxx
gateway 10.167.xxx.xxx
dns-nameservers 10.167.xxx.xxx
其中静态ip,掩码,网关,dns由公司IT提供。注意address是IP地址,不要改错了,否则你可能要去机房才能连接上机器!!!
然后重启网络服务。DNS不要用网上说的什么8.8.8.8 / 8.8.4.4 / 等等。这些外网地址在内网环境下是不一定能被允许访问的。应该使用什么DNS应该咨询组织IT。
$ sudo /etc/init.d/networking restart
还是报错:
xfce4-volumed/xfce4-volumed_0.2.0-0ubuntu2_amd64.deb Could not resolve 'cn.archive.ubuntu.com'
E: Failed to fetch http://cn.archive.ubuntu.com/ubuntu/pool/universe/x/xscreensaver/xscreensaver-data_5.34-2ubuntu1_amd64.deb Could not resolve 'cn.archive.ubuntu.com'
E: Failed to fetch http://cn.archive.ubuntu.com/ubuntu/pool/universe/x/xscreensaver/xscreensaver_5.34-2ubuntu1_amd64.deb Could not resolve 'cn.archive.ubuntu.com'
E: Failed to fetch http://cn.archive.ubuntu.com/ubuntu/pool/universe/x/xubuntu-artwork/xubuntu-icon-theme_16.04.2_all.deb Could not resolve 'cn.archive.ubuntu.com'
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?
步骤五:如果还是报错,重启服务器
E: Failed to fetch http://cn.archive.ubuntu.com/ubuntu/pool/universe/x/xfce4-pulseaudio-plugin/xfce4-pulseaudio-plugin_0.2.4-1_amd64.deb Something wicked happened resolving 'cn.archive.ubuntu.com:http' (-5 - No address associated with hostname)
E: Failed to fetch http://cn.archive.ubuntu.com/ubuntu/pool/universe/x/xfce4/xfce4_4.12.2_all.deb Something wicked happened resolving 'cn.archive.ubuntu.com:http' (-5 - No address associated with hostname)
E: Failed to fetch http://cn.archive.ubuntu.com/ubuntu/pool/universe/x/xfce4-notifyd/xfce4-notifyd_0.2.4-3ubuntu1_amd64.deb Something wicked happened resolving 'cn.archive.ubuntu.com:http' (-5 - No address associated with hostname)
E: Failed to fetch http://cn.archive.ubuntu.com/ubuntu/pool/universe/x/xfce4-volumed/xfce4-volumed_0.2.0-0ubuntu2_amd64.deb Something wicked happened resolving 'cn.archive.ubuntu.com:http' (-5 - No address associated with hostname)
E: Failed to fetch http://cn.archive.ubuntu.com/ubuntu/pool/universe/x/xscreensaver/xscreensaver-data_5.34-2ubuntu1_amd64.deb Something wicked happened resolving 'cn.archive.ubuntu.com:http' (-5 - No address associated with hostname)
E: Failed to fetch http://cn.archive.ubuntu.com/ubuntu/pool/universe/x/xscreensaver/xscreensaver_5.34-2ubuntu1_amd64.deb Something wicked happened resolving 'cn.archive.ubuntu.com:http' (-5 - No address associated with hostname)
E: Failed to fetch http://cn.archive.ubuntu.com/ubuntu/pool/universe/x/xubuntu-artwork/xubuntu-icon-theme_16.04.2_all.deb Something wicked happened resolving 'cn.archive.ubuntu.com:http' (-5 - No address associated with hostname)
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?
步骤六:如果还是报错:
1,打开firefox, $ sudo firefox
2,设置代理链接 :菜单-preference-advanced-network-connection-settings-automatic proxy configuration URL-粘贴http://xxx.pac/的代理上网地址(由IT提供)-OK
3,访问www.baidu.com,提示insecure,不管它,加入例外->confirm exceptions。然后再打开百度或者新浪,发现可以打开了。但是APT还是不能用
4,新建或编辑/etc/apt/apt.conf文件,加入代理:
$ sudo vi /etc/apt/apt.conf
加入
Acquire::http::Proxy "http://10.xxx.xxx.xxx:8080/";
5,重新使用apt
$ sudo apt-get update
$ sudo apt-get install xrdp
可以了。