Ubuntu网络设置

IP配置方式一:IP自动获取(DHCP)

只需修改/etc/network/interfaces文件即可,修改后内容如下:

auto eth0 # 设置eth0开机自动加载

iface eth0 inet dhcp# 定义网络接口eth0为Internet,DHCP方式。


IP配置方式二:IP手动配置(Static)

修改/etc/network/interfaces文件:

auto eth0

iface eth inet static

address 10.0.2.25

gateway 10.0.2.25

netmask 255.255.255.0


配置DNS方式一,修改/etc/network/interfaces,增加内容如下

dns-nameservers 8.8.8.8 8.8.4.4

dns-search foo.org bar.com

 

配置DNS方式二,修改/etc/dhcp/dhclient.conf,

将prepend domain-name-servers x.x.x.x注释打开,并将x.x.x.x修改成你心目中的dns


关于主机名:

直接修改/etc/hostname文件即可,文件中仅存主机名


主机访问控制:

 通过修改tcpd的配置文件/etc/hosts.allow与/etc/hosts.deny来完成,当配置冲突时,以前者配置为准,

因此,二者仅需其一即可完成配置。二者同时存在的原因是这样使得配置更加清晰,即允许规则放在hosts.allow中,禁止规则放在hosts.deny中。

文件中一条规则占用一行,格式为:

daemon_list:client_list[:shell_list],其中,daemon所示daemon进程名,必须在/etc/rc.d/(BSD风格的启动脚本)或/etc/init.d(SystemV风格的启动脚本)下出现

sshd的配置例子:

# /etc/hosts.allow

ALL:127.0.0.1 # 允许本机访问所有服务

sshd:10.0.2.0/255.255.255.0# 允许10.0.3.0网段的IP访问ssh服务

sshd:10.0.3.0/24# 允许10.0.3.0网段的IP访问ssh服务

# /etc/hosts.deny

ALL:ALL # 禁止所有访问


注意:修改网络配置文件后,要重启网络接口,使用命令:/etc/init.d/networking restart

你可能感兴趣的:(Ubuntu网络设置)