ubuntu 网络设置

注意:Ubuntu 12.04 版本为例

1. 设置IP
设置文件路径:/etc/network/interfaces
root@test01:~# vi /etc/network/interfaces 
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
#这边的设置是本地回路
# The primary network interface
#eth0 就是网卡,如果电脑有多块网卡,比如还会有eth1……,都可以在这里进行设置。
auto eth0
#iface eth0 inet dhcp
#iface eth0 inet 设置为dhcp是动态获取IP,设置为static则用自定义的IP。这边要自定义IP地址,所以选择static选项。
iface eth0 inet static
#设置 IP地址
address 192.168.1.100
#设置掩码
netmask 255.255.255.0
#network 192.168.1.0
#broadcast 192.168.1.255
#设置网关
gateway 192.168.1.254
# dns-* options are implemented by the resolvconf package, if installed
#设置 DNS,和 /etc/resolv.conf 一致
dns-nameservers 192.168.1.1
dns-search localdomain

2.设置 DNS
ip设置好后,如果直接ping www.baidu.com会发现ping不通,因为dns还没设置,编辑/etc/resolv.conf,加上dns服务器地址。
root@test01:~#vi /etc/resolv.conf 
nameserver 192.168.1.1

3.设置主机名
root@test01:~#vi /etc/hostname
test01
root@test01:~#hostname test01

4.重新启动网络服务:/etc/init.d/networking restart
重启好后,用ifconfig看下eth0,是不是改成自己需要的IP地址了。
root@test01:~#/etc/init.d/networking restart

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值