关于VMware中安装Ubuntu18.04.4设置静态ip以及apt换源的问题与解决

Faith ·
更新时间:2024-11-13
· 862 次阅读

最近开始学着使用Ubuntu操作系统
有着安装CentOS的经验,本安装过程会很简单,但发现还是有好多地方不一样的,甚至想骂娘,o(╥﹏╥)o。
本篇作为整理,中间详细步骤就不列出

主要问题在apt换源设置静态ip(网上关于虚拟机中ip设置直接在更改虚拟机网络编辑器中设置还原默认设置,当然这也可以,但我因为一些原因得设置静态ip)

设置静态ip:

查看虚拟机网络编辑器中 子网ip、子网掩码、网关ip
在这里插入图片描述

修改 /etc/hosts 文件:

localhost前面的ip不用改不用注释,hostname前面的ip地址改为自己想要设置的ip,hostname在/etc/hostname更改

在这里插入图片描述

修改 /etcresolv.conf 文件:

在文件的内容尾部添加一行:nameserver:114.114.114.114

修改 /etc/netplan/***.yaml 文件

这个yaml 文件最恶心,第一次接触,格式要求那么多
1.不能以 tab 键来间隔
2.每行:冒号后面得空一格
3.层次结构明显
4.addresses后面中括号中填写子网ip地址后面加 /24 (24表示子网掩码的长度是24位)

关键之关键是看清配置总共分为五个层次,逐层向后至少空一格,
第一层-network:
第二层-- ethernets:
第三层--- ens33: #配置的网卡名称
第四层----addresses: #设置本机IP及掩码
第四层----gateway4: #设置网关
第四层----nameservers:
第五层-----addresses: [114.114.114.114, 8.8.8.8] #设置DNS在这里插入图片描述

查看修改ubuntu网络设置对不对
在这里插入图片描述

ping 测试
在这里插入图片描述

apt换源

复制源文件,备份

sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak

添加源

sudo vim /etc/apt/sources.list

添加内容

deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse

apt更新

sudo apt-get update 更多源:

中科大源:

deb https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse

163源:

deb http://mirrors.163.com/ubuntu/ bionic main restricted universe multiverse deb http://mirrors.163.com/ubuntu/ bionic-security main restricted universe multiverse deb http://mirrors.163.com/ubuntu/ bionic-updates main restricted universe multiverse deb http://mirrors.163.com/ubuntu/ bionic-proposed main restricted universe multiverse deb http://mirrors.163.com/ubuntu/ bionic-backports main restricted universe multiverse deb-src http://mirrors.163.com/ubuntu/ bionic main restricted universe multiverse deb-src http://mirrors.163.com/ubuntu/ bionic-security main restricted universe multiverse deb-src http://mirrors.163.com/ubuntu/ bionic-updates main restricted universe multiverse deb-src http://mirrors.163.com/ubuntu/ bionic-proposed main restricted universe multiverse deb-src http://mirrors.163.com/ubuntu/ bionic-backports main restricted universe multiverse

清华源:

deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
作者:变秃,才能变强



VMware ubuntu ip apt 静态ip

需要 登录 后方可回复, 如果你还没有账号请 注册新账号
相关文章