一.环境
Windows10 64位
VMware-workstation-14.1.1
Ubuntu16.04.3-Server-amd64
二.步骤
2.1 下载VMare,安装VMware
2.2 下载Ubuntu16.04.3 , 安装Linux系统
(1) 在VMware中,选择“文件-开始-新建虚拟机”, 然后进入如下页面,选择完镜像文件与安装地址,开始安装。
(2)Ubuntu安装过程中,如出现卡顿,可直接关机再重新开机。其中,设置虚拟机内存2GB,联网模式为桥接模式。
(3)安装成功,登录进入系统
三、配置固定IP地址
3.1 修改Linux配置文件,配置网络IP地址,子网掩码及网关地址。
(1)通过ipconfig查看本地(Windows)IP地址信息。
本地连接WIFI,所以查看WLAN信息,否则查看以太网适配器信息。
提取有效信息:
IPv4地址: 10.215.19.137 (教育网内都是私有IP)
子网掩码: 255.255.255.224
默认网关: 10. 215.19.129
(2)根据本地IP地址,配置Linux的IP地址,使它们在同一网段内,可以通过桥接模式共同上网。
其中,子网掩码与默认网关与本地信息保持一致, IPv4地址选取本网段内即可,此处随机选取10.215.19.133
然后,通过本地 ping 验证,选定的IP地址暂无人用,才可以被配置为Linux的IP地址。
无人应答,验证成功。
(3)通过ifconfig查看Linux下网卡信息。(此处是配置好了的)
提取关键信息:
inet addr:10.215.19.133
Mask: 255.255.255.224
zy@ubuntu:~$ ifconfig
ens33 Link encap:Ethernet HWaddr 00:0c:29:5f:af:81
inet addr:10.215.19.133 Bcast:10.215.19.159 Mask:255.255.255.224
inet6 addr: fe80::20c:29ff:fe5f:af81/64 Scope:Link
inet6 addr: 2001:da8:215:cf9c:20c:29ff:fe5f:af81/64 Scope:Global
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:400 errors:0 dropped:0 overruns:0 frame:0
TX packets:212 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:42794 (42.7 KB) TX bytes:23376 (23.3 KB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:104 errors:0 dropped:0 overruns:0 frame:0
TX packets:104 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1
RX bytes:5200 (5.2 KB) TX bytes:5200 (5.2 KB)
(4)正式开始配置
首先进入配置文件路径。(这里由于vim编辑器还没有安装,所以选择自带的 vi编辑)
sudo vi /etc/network/interfaces
interfaces文件内容:
由于ens33配置为dpch,所以IP会动态变化,这里主要对其进行调整。
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto ens33
***iface ens33 inet dhcp***
# This is an autoconfigured IPv6 interface
iface ens33 inet6 auto
(5) 修改配置文件。
注释 iface ens33 inet dhcp
添加我们选定好的固定IP地址,子网掩码与网关地址。此处在 vi 中使用 ‘i’ 从命令模式切换到输入模式,输入完成后按下Esc键,并输入" :wq! " 实现文件的存盘与退出。
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto ens33
# iface ens33 inet dhcp
iface ens33 inet static
address 10.215.19.133
gateway 10.215.19.129
netmask 255.255.255.224
# This is an autoconfigured IPv6 interface
iface ens33 inet6 auto
四、修改DNS
(1)首先进入配置文件路径,打开文件
sudo vi /etc/resolvconf/resolv.conf.d/base
(2)这里是一个空文档,直接添加内容。
8.8.8.8是谷歌的域名解析服务器
nameserver 8.8.8.8
五、配置完成,验证网络状态
(1)重启虚拟机
sudo reboot
(2) 输入ifconfig, 查看网络信息
zy@ubuntu:~$ sudo vim /etc/network/interfaces
[sudo] password for zy:
zy@ubuntu:~$ ifconfig
ens33 Link encap:Ethernet HWaddr 00:0c:29:5f:af:81
inet addr:10.215.19.133 Bcast:10.215.19.159 Mask:255.255.255.224
inet6 addr: fe80::20c:29ff:fe5f:af81/64 Scope:Link
inet6 addr: 2001:da8:215:cf9c:20c:29ff:fe5f:af81/64 Scope:Global
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:837 errors:0 dropped:0 overruns:0 frame:0
TX packets:393 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:84643 (84.6 KB) TX bytes:47180 (47.1 KB)
(3)验证网络状态
在虚拟机内 Ping 网关IP地址10.215.19.129,WindowsIP地址 10.215.19.137 和 www.baidu.com
在Windows内 Ping 虚拟机IP地址 10.215.19.129
理想情况下,都能Ping通。 【Ctrl+C 停止发包请求】
(4)(特殊情况)注意
这里由于是在校园网内,校园网有额外的网关验证(学号+密码),所以此时状态为:
windows可以ping通虚拟机IP地址
虚拟机可以ping通网关IP地址,却ping不通windowsIP地址和外部IP地址。
图形化界面的用户,可以直接通过浏览器登录验证地址,输入账号密码即可。
非图形化界面的用户,只能通过指令操作。
这里分析校园网网关信息(具有特殊性,各地不相同),得出此处指令为:
curl --silent -d "DDDDD=账号&upass=密码&AMKKey=" "http://10.3.8.211"
或
curl 'http://10.3.8.211' --data "DDDDD=2017xxxxxx&upass=yourpassword&0MKKey="
登出指令为:
cur http://10.3.8.211/F.htm
六、apt-get 升级
(1)由于系统不具备curl工具,需要进行安装
sudo apt-get install curl
(2)如果安装失败,说明 需要更新源, 进行 apt-get 升级
(3)进入更新源,配置路径
cd /etc/apt
(4) 拷贝sourcelists以做备份
sudo cp sources.list sources.list.backup
(5)进入配置文件,添加源
此处选择的是清华大学的镜像源,网址:清华-ubuntu镜像源
添加以下内容到sources.list文件中
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted universe multiverse
# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-proposed main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-proposed main restricted universe multiverse
(6)升级apt-get
注意选择无需额外网关认证的网络,才能连接成功,进行下载
sudo apt-get update
(6) 后续软件安装
sudo apt-get install vim-gtk
sudo apt-get install curl
七、配置远程连接
7.1 在Linux上安装ssh服务
首先可以通过如下命令,验证系统是否已有ssh。 若无反应,则是没有。
ps -e|grep ssh
ssh安装
sudo apt-get install openssh-server
再次验证,效果如下,说明安装成功
7.2 在Windows下安装远程连接工具
这里推荐 XSHELL
选择 “文件-新建-新建会话”。 在名称和主机两栏中填入 Linux的IP地址。点击确定,输入账号密码,连接成功。此后即可在此异地操作Linux系统。
八、配置编译环境
安装GCC与G++
其中build-essential是编译程序所需库
sudo apt-get install build-essential
sudo apt-get install gcc
sudo apt-get install g++