欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

ubuntu的常用配置

程序员文章站 2024-03-08 18:05:16
...

1. 网卡设置

sudo vim /etc/network/interfaces

auto ens33
iface ens33 inet static
address 192.168.8.100
netmask 255.255.255.0
gateway 192.168.8.2
dns-nameserver 119.29.29.29
#dns-nameservers 221.130.33.52 221.130.33.60

vim /etc/resolv.conf
nameserver 192.168.10.1
#阿里的DNS:223.5.5.5

sudo /etc/init.d/networking restart

sudo vim /etc/NetworkManager/NetworkManager.conf
打开该文件,将“managed=false”修改为“managed=true”

sudo service network-manager restart

2. Ubuntu 16.04 修改为几个国内更新源

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

把下面的任意一下复制到source.list中去,并覆盖原来的文件内容。
中科大源
deb http://mirrors.ustc.edu.cn/ubuntu/ xenial main restricted universe multiverse
deb http://mirrors.ustc.edu.cn/ubuntu/ xenial-security main restricted universe multiverse
deb http://mirrors.ustc.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
deb http://mirrors.ustc.edu.cn/ubuntu/ xenial-proposed main restricted universe multiverse
deb http://mirrors.ustc.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu/ xenial main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu/ xenial-security main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu/ xenial-proposed main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse

东北大学源
deb-src http://mirror.neu.edu.cn/ubuntu/ xenial main restricted #Added by software-properties
deb http://mirror.neu.edu.cn/ubuntu/ xenial main restricted
deb-src http://mirror.neu.edu.cn/ubuntu/ xenial restricted multiverse universe #Added by software-properties
deb http://mirror.neu.edu.cn/ubuntu/ xenial-updates main restricted
deb-src http://mirror.neu.edu.cn/ubuntu/ xenial-updates main restricted multiverse universe #Added by software-properties
deb http://mirror.neu.edu.cn/ubuntu/ xenial universe
deb http://mirror.neu.edu.cn/ubuntu/ xenial-updates universe
deb http://mirror.neu.edu.cn/ubuntu/ xenial multiverse
deb http://mirror.neu.edu.cn/ubuntu/ xenial-updates multiverse
deb http://mirror.neu.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirror.neu.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse #Added by software-properties
deb http://archive.canonical.com/ubuntu xenial partner
deb-src http://archive.canonical.com/ubuntu xenial partner
deb http://mirror.neu.edu.cn/ubuntu/ xenial-security main restricted
deb-src http://mirror.neu.edu.cn/ubuntu/ xenial-security main restricted multiverse universe #Added by software-properties
deb http://mirror.neu.edu.cn/ubuntu/ xenial-security universe
deb http://mirror.neu.edu.cn/ubuntu/ xenial-security multiverse

清华大学
# deb cdrom:[Ubuntu 16.04 LTS _Xenial Xerus_ - Release amd64 (20160420.1)]/ xenial main restricted
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security multiverse

阿里云源
# deb cdrom:[Ubuntu 16.04 LTS _Xenial Xerus_ - Release amd64 (20160420.1)]/ xenial main restricted
deb-src http://archive.ubuntu.com/ubuntu xenial main restricted #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
deb http://mirrors.aliyun.com/ubuntu/ xenial multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse #Added by software-properties
deb http://archive.canonical.com/ubuntu xenial partner
deb-src http://archive.canonical.com/ubuntu xenial partner
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-security multiverse

sudo apt-get update

3. Ubuntu的图形网络配置内容都配置到哪里了?

sudo cat /etc/NetworkManager/system-connections/Wired\ connection\ 2

[connection]
id=Wired connection 2
uuid=18fcdfd4-e0b5-3343-9dec-78a06270671a
type=ethernet
autoconnect-priority=-999
permissions=
secondaries=
timestamp=1540015753

[ethernet]
duplex=full
mac-address=00:0C:29:C7:A9:B9
mac-address-blacklist=

[ipv4]
address1=192.168.135.100/24
dns-search=
method=manual

[ipv6]
addr-gen-mode=stable-privacy
dns-search=
ip6-privacy=0
method=auto

总结:

1)配置 /etc/network/interfaces文件

此为Linux传统的配置方式,通过address、netmask、gateway等字段来配置。DNS信息保存在/etc/resolv.conf文件中。

2)配置/etc/NetworkManager/system-connections目录下的文件

这是配合图形界面配置程序NetworkManager,可以在桌面通过图形界面配置,配置信息保存在这个目录下的文件中。
两种配置方法只能选用一种,如果eth0同时出现在两个配置文件中,则以 /etc/network/interfaces中的配置为准。

4. 考虑到ubuntu的图形界面还是比较耗内存的,所以决定将其关闭

	1)、首先我们修改grub文件,把其中的GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"改为GRUB_CMDLINE_LINUX_DEFAULT="text",
	还有取消GRUB_TERMINAL=console之前的注释#。
     
     $sudo vim /etc/default/grub

	2)、然后更新我们的grub。

  $sudo update-grub

	3)、设置开机进入字符界面。

  $sudo systemctl set-default multi-user.target

	4)、然后我们重新启动我们的ubuntu,直接就进入字符界面了。

  $sudo reboot 

	5)、在字符界面下要登录图形界面可以使用以下的命令。

  $sudo systemctl start lightdm

	6)、如果要回到开机启动直接进入图形界面,可以执行以下的命令。

  $sudo systemctl set-default graphical.target

5. 修改主机名,以及解析主机名

第一步:修改主机名:

  vim  /etc/hostname

第二步:修改网络解析名称:

  vim /etc/hosts

第三步:重启网络配置服务(或者刷新dns):

  sudo /etc/init.d/networking restart(sudo /etc/init.d/dns-clean start)

6. 如何切换到root

sudo su root
passwd root
定义root的密码,之后登录普通用户就可以su root了。

再或者直接修改root的密码
sudo passwd root
相关标签: ubuntu配置