Linux之网络配置

来源:互联网 发布:vb 读取西门子plc 编辑:程序博客网 时间:2024/04/28 11:11

 这次是在写作业时遇到的问题~想到干脆些个关于Linux下配置网络的文字吧。

我还是以ubuntu10.10为准

我喜欢的做法是:

sudo vi /etc/network/interface

然后,写配置文件

 

auto lo

iface lo inet loopback

auto eth0

iface eth0 inet static

hwaddress ether 00:e0:4c:22:26:00

address 192.168.1.14

netmask 255.255.255.0

gateway 192.168.1.254

broadcast 192.168.1.255

dns-nameservers 202.102.134.68

以上是静态的。若是动态, iface eth0 inet dhcp

如果有/etc/resolve.conf则dns在该文件中设置。

nameserver 202.102.128.68

nameserver 202.102.134.68

然后,重启服务 sudo /etc/init.d/networking restart

而我们老师喜欢的一种做法是,用ifconfig。我也查了查

ifconfig eth0 192.168.1.14/255.255.255.0

ifconfig eth0 up

我还用过一个语句,sudo ip link set eth0 up
下面还是转载点资料以供参考
///////////////////////////////////////////////以下转载来的///////////////////////////////////////////////
/etc/sysconfig/network 包括主机基本网络信息,用于系统启动
 
/etc/sysconfig/network-script/ 此目录下是系统启动最初始化网络的信息
 
/etc/sysconfig/network-script/ifcfg-eth0 网络配置信息
 
/etc/xinetd.conf 定义了由超级进程XINETD启动的网络服务
 
/etc/protocols 设定了主机使用的协议以及各个协议的协议号
 
/etc/services 设定了主机的不同端口的网络服务
 
// 网络配置工具
 
# redhat-config-network
 
 /* 使用ifconfig命令配置并查看网络接口情况 */
 
//配置eth0的IP,同时激活设备
 
# ifconfig eth0 192.168.168.119 netmask 255.255.255.0 up
 
//配置eth0别名设备 eth0:1 的IP,并添加路由
 
# ifconfig eth0:1 192.168.168.110
 
# route add –host 192.168.168.110 dev eth0:1
 
//激活(禁用)设备
 
# ifconfig eth0:1 up(down)
 
//查看所有(指定)网络接口配置
 
# ifconfig (eth0)
 
 /* 使用route 命令配置路由表 */
 
//添加到主机路由
 
# route add –host 192.168.168.110 dev eth0:1
 
# route add –host 192.168.168.119 gw 192.168.168.1
 
//添加到网络的路由
 
# route add –net IP netmask MASK eth0
 
# route add –net IP netmask MASK gw IP
 
# route add –net IP/24 eth1
 
//添加默认网关
 
# route add default gw IP
 
//删除路由
 
# route del –host 192.168.168.110 dev eth0:1
 
 /* 常用命令 */
 
# traceroute www.pconline.com.cn
 
# ping www.pconline.com.cn
 
//显示网络接口状态信息
 
# netstat –I
 
//显示所有监控的服务器的Socket和正在使用Socket的程序信息
 
# netstat –lpe
 
//显示内核路由表信息
 
# netstat –r
 
# netstat –nr
 
//显示TCP/UDP传输协议的连接状态
 
# netstat –t
 
# netstat –u
 
//更改主机名
 
# hostname myhost
 
//查看ARP缓存
 
# arp
 
//添加
 
# arp –s IP MAC
 
//删除
 
# arp –d IP
 
 /* 运行级别与网络服务 */
 
//查看当前运行级别
 
# runlevel
 
//运行级别的切换
 
# init
 
# telinit
 
////////////////////////转载来自http://www.pconline.com.cn/pcjob/system/linux/others/0410/470884.html/////////////////////////////////

 

原创粉丝点击