Ubuntu局域网中设置代理服务器上网和设置静态IP


1.使用代理服务器上网

我们想要使用机器A通过机器B上网,可以使用如下方法:

1.首先确保机器B可以上网。

2.在机器B上安装squid软件,$sudo apt-get install squid,安装完成后在网上down一个squid配置文件squid.conf,然后覆盖到/etc/squid/下的同名文件

3.在机器B器上测试代理服务器,$sudo service squid start 如果看见squid start/running,process 1726(进程号会不同)字样,再执行sudo service squid stop,看到squid stop/waiting字样就再执行$sudo service squid start,$sudo service squid restart.如果2次都看到了squid start/running,process 1726字样就说明基本上OK了。

4.然后在机器A上设置网络代理,将原来的代理改为你机器B的ip地址,端口号改为3128即可。ip地址可用$ifconfig查看。

5.在机器A上开一个网页,如果打不开那么就把squid删了再重装。$sudo apt-get autoremove squid

PS:开机后不需要输入密码就可以启动代理服务器。


2.设置静态IP

Ubuntu的网络配置信息是保存在 /etc/network/interfaces 文件中,使用Vim打开配置文件,默认是自动获取IP的配置.如下:

# The primary network interface

auto lo

iface lo inet loopback

下面我们将其设置成静态IP.

第一步:屏蔽掉自动获取IP的设置

auto lo将这一行屏蔽掉

iface lo inet loopback将这一行屏蔽掉

修改之后的内容如下:

# The primary network interface

#auto lo

auto eth0

#iface eth0 inet dhcp

第二步:添加静态IP的信息

# The primary network interface

iface eth0 inet static

address 45.111.38.58

netmask 255.255.255.0

gateway 45.111.38.254

PS:这里的address要求不能是已分配给其他人的IP地址。

重启网络:sudo /etc/init.d/networking restart

以上步骤完成之后只要重新启用一下网络就OK了.

相关内容