ubuntu 常用设置

●1 问题:使用virt-manager创建虚拟机时,Virtual network 'default':NAT(Inactive)

解决方法:
1,查看网络状态
sudo virsh net-list --all
2,如果自动开始为no,做如下设定。
sudo virsh net-autostart default
3,起动网络
sudo virsh net-start default

●如果又出现如下错误:
internal error: Network is already in use by interface virbr0
解决方法:
Identify the name of the bridge associated with the 'default' network.

You can find out the bridge name in the default network template (/etc/libvirt/qemu/networks/default.xml).

In most cases, the bridge name is virbr0.

Remove that bridge as follows.

$ sudo  ifconfig  virbr0  down

$ sudo brctl delbr virbr0(Note: not necessary)
Now start the 'default' network using virsh command.

$ sudo virsh net-start default
This will automatically re-create the virbr0 bridge.

再次确认网络状态:
$ sudo virsh net-list --all
参考:
http://blog.csdn.net/liukuan73/article/details/43238955
http://ask.xmodulo.com/network-default-is-not-active.html

●2 ubuntu代理上网
方法1:
仅仅让apt-get使用http代理(仅当前有效)。
执行:exporthttp_proxy="http://用户名:密码@代理IP:代理端口"

方法2:
仅仅让apt-get一直使用http代理。
sudo gedit /etc/apt/apt.conf
在apt.conf文件加入:
Acquire::http::Proxy "http://yourproxyaddress:proxyport/".

方法3:
在主目录的.bashrc文件中添加两行(都能使用代理)。
sudo vi ~/.bashrc

http_proxy=http://yourproxyaddress:proxyport
export http_proxy

●3 Ubuntu 网卡配置

自ubuntu 15之后,网卡名称不叫eth0了(现在为ensXX),可以通过ifconfig -a 查看。

※当然还可以把网卡名称改回eth0,不过认为没有必要。

如果执行命令:ifconfig 只显示 lo,不显示网卡。

可以通过编辑/etc/network/interfaces文件,追加以下语句:

auto lo
iface lo inet loopback
在后面添加内容:

#两种方法任选一个
#1、获取动态配置:
auto eth0
iface eth0 inet dhcp
#2、获取静态配置:
auto eth0
iface eth0 inet static
address 192.168.0.2
netmask 255.255.255.0
gateway 192.168.0.1

dns-nameservers 192.168.0.1

●备注
修改/etc/network/interfaces这个文件,配置IP、网关。里面有个参数DNS,对应的参数名为dns-nameservers,
这里设置的优先级比resolv.conf高,也就是网络会从这里读取DNS配置,如果没配置才去看resolv.conf里面的设置,
因此在这里面配置DNS更简单。

配置完成后,重启网络:
sudo service networking restart
或者
sudo /etc/init.d/networking restart

也可以重启网卡:
sudo ifconfig eth0 down
sudo ifconfig eth0 up
重启网卡对别的网卡无影响。

GUI版配置如下:

●4,Ubuntu默认不允许root通过ssh直接登录,设置如下(允许root登录):
编辑vim /etc/ssh/sshd_config文件,将PermitRootLogin 的值改为yes。
如下所示:
# Authentication:
LoginGraceTime 120
PermitRootLogin yes
StrictModes yes
 
●5,以下命令确认CPU支持虚拟化。
euser01@ubuntu:~$ egrep -o '(vmx|svm)' /proc/cpuinfo
显示结果:vmx
          vmx

●6,主机名称配置文件(/bin/hostname)

▪查看当前主机的主机名称:

sudo /bin/hostname

▪设置当前主机的主机名称:

sudo /bin/hostname newname

系统启动时从/etc/hostname来读取主机的名称.

------山的那一边
原文地址:https://www.cnblogs.com/mountain2011/p/7009392.html