当前位置 主页 > 服务器问题 > Linux/apache问题 >
一、快速修改,重启后设置就没了
ifconfig eth0 192.168.1.22 netmask 255.255.255.0 uproute add default gw 192.168.1.2
二、修改配置文件,重启设置还在
(一)ubuntu 版本命令行设置静态IP
修改 /etc/network/interfaces
# This filedescribes the networ k interfaces available onyour system# and how toactivate them. For more information, seeinterfaces(5).# The loopbacknetwork interfaceauto loiface lo inetloopback# The primarynetwork interfaceauto eth0iface eth0 inet staticaddress 192.168.1.100netmask 255.255.255.0gateway 192.168.1.1在/etc/resolv.conf添加nameserver 192.168.1.1nameserver 220.170.64.68重启网卡:/etc/init.d/networking restart
(二)SUSE
1、修改IP地址
修改/etc/sysconfig/network/ifcfg-eth0文件
BOOTPROTO='static'BROADCAST=''ETHTOOL_OPTIONS=''IPADDR='192.168.1.2/24'MTU=''NAME='eth0'NETWORK=''REMOTE_IPADDR=''STARTMODE='auto'USERCONTROL='no'
2、设置网关
修改/etc/sysconfig/network/routesdefault 192.168.1.1
3、设置DNS
nameserver 202.96.128.86nameserver 202.96.134.33
4、重新启动网络配置
servicenetwork restart
(三)redhat linux版本命令行设置IP:
快速设置ip,但重启后就没了
ifconfig eth0 1.1.1.1
然后编辑/etc/sysconfig/network-scripts/ifcfg-eth0,修改ip
1、设置静态IP地址
[root@file]$ vi ifcfg-eth0 DEVICE=eth0 ONBOOT=yes BOOTPROTO=static IPADDR=219.136.241.211 NETMASK=255.255.255.128 GATEWAY=219.136.241.254
2、设置网关
vi/etc/sysconfig/network NETWORKING=yes HOSTNAME=Aaron GATEWAY=192.168.1.1
3、设置DNS
[root@file]$ vi resolv.conf nameserver202.96.128.68 nameserver219.136.241.206
4、重新启动网络配置
命令:servicenetwork restart 或/etc/init.d/networkrestart
三、例子
(1) 修改ip地址
即时生效: # ifconfigeth0 192.168.0.20 netmask 255.255.255.0 启动生效: 修改/etc/sysconfig/network-scripts/ifcfg-eth0
(2) 修改default gateway
即时生效: # route adddefault gw 192.168.0.254 启动生效: 修改/etc/sysconfig/network-scripts/ifcfg-eth0 修改dns 修改/etc/resolv.conf 修改后可即时生效,启动同样有效
(3) 修改host name
即时生效: # hostname fc2 启动生效: 修改/etc/sysconfig/network ps: DEVICE=eth0 BOOTPROTO=static IPADDR=192.168.8.85 NETMASK=255.255.248.0 GATEWAY=192.168.8.1 HWADDR=00:0uu3:47:2C:D5:40 ONBOOT=yes