Linux 配置启动方式,机器名,网络

一 配置机器启动方式

 命令:vi /etc/inittab

[root@localhost puppet]# vi /etc/inittab
# inittab is only used by upstart for the default runlevel.
#
# ADDING OTHER CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM.
#
# System initialization is started by /etc/init/rcS.conf
#
# Individual runlevels are started by /etc/init/rc.conf
#
# Ctrl-Alt-Delete is handled by /etc/init/control-alt-delete.conf
#
# Terminal gettys are handled by /etc/init/tty.conf and /etc/init/serial.conf,
# with configuration in /etc/sysconfig/init.
#
# For information on how to write upstart event handlers, or how
# upstart works, see init(5), init(8), and initctl(8).
#
# Default runlevel. The runlevels used are:
#   0 - halt (Do NOT set initdefault to this)
#   1 - Single user mode
#   2 - Multiuser, without NFS (The same as 3, if you do not have networking)
#   3 - Full multiuser mode
#   4 - unused
#   5 - X11
#   6 - reboot (Do NOT set initdefault to this)
#
id:5:initdefault:
  注:
  •  id:3 :命令模式启动
  •  id:5 :XWindows启动
重启生效

二修改机器名

命令:vi /etc/sysconfig/network
[root@AY131216151615898d19Z ~]# vi /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=dc-fetch-000    【机器名】

注:
  1. NETWORKING=yes:表示系统是否使用网络,一般设置为yes。如果设为no,则不能使用网络,而且很多系统服务程序将无法启动
  2. HOSTNAME=centos:设置本机的主机名,这里设置的主机名要和/etc/hosts中设置的主机名对应
重启生效

三 修改网络

(一)网络服务
1 重启网络服务器
命令: service network restart  或   /etc/init.d/network restart
[root@BigData-01 puppet]# service network restart
Shutting down loopback interface:  [  OK  ]
Bringing up loopback interface:  [  OK  ]
Bringing up interface eth0:  Active connection state: activated
Active connection path: /org/freedesktop/NetworkManager/ActiveConnection/2
[  OK  ]
 
2 开启关闭防火墙
命令: service iptables start , service iptables stop , service iptables restart
[root@localhost ailk]# service iptables status
iptables: Firewall is not running.
[root@localhost ailk]# service iptables
Usage: iptables {start|stop|restart|condrestart|status|panic|save}
(二)网络环境
1 主机IP映射     
 命令:vi /etc/hosts
[root@BigData-01 puppet]# vi /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
8.8.8.10 BigData-01 ZK-01
注:
  1. 第一部份:网络IP地址;
  2. 第二部份:
  •      主机名.域名,注意主机名和域名之间有个半角的点,比如 localhost.localdomain
  •      主机名(主机名别名) ,其实就是主机名;
及时生效
2 静态IP设置
命令: cd /etc/sysconfig/network-scripts/
           vi ifcfg-eth0
[root@localhost sysconfig]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# vi ifcfg-eth0
DEVICE="eth0"
BOOTPROTO="static"
IPADDR="8.8.8.2"
NETMASK="255.255.255.0"
NETWORK="8.8.8.0"
#HWADDR="00:0C:29:8E:42:B2"
GATEWAY="8.8.8.1"
ONBOOT="yes"
注:
  1. DEVICE=eth0:描述网卡对应的设备别名,例如ifcfg-eth0的文件中它为eth0
  2. BOOTPROTO=static:设置网卡获得ip地址的方式,可能的选项为static,dhcp或bootp,分别对应静态指定的 ip地址,通过dhcp协议获得的ip地址,通过bootp协议获得的ip地址
  3. BROADCAST=192.168.0.255:对应的子网广播地址
  4. HWADDR=00:07:E9:05:E8:B4:对应的网卡物理地址
  5. IPADDR=12.168.0.33:如果设置网卡获得 ip地址的方式为静态指定,此字段就指定了网卡对应的ip地址
  6. NETMASK=255.255.255.0:网卡对应的网络掩码
  7. NETWORK=192.168.0.0:网卡对应的网络地址
  8. GATEWAY=192.168.0.1:设置本机连接的网关的IP地址
重启网络服务生效
3 设置DNS
命令:
[root@BigData-01 puppet]# vi /etc/resolv.conf
# Generated by NetworkManager


# No nameservers found; try putting DNS servers into your
# ifcfg files in /etc/sysconfig/network-scripts like so:
#
# DNS1=xxx.xxx.xxx.xxx
# DNS2=xxx.xxx.xxx.xxx
# DOMAIN=lab.foo.com bar.foo.com
注:
      DNS1 即是DNS服务器IP地址,第一个是首选,第二个是备用

猜你喜欢

转载自shihlei.iteye.com/blog/2083567