如何在Linux中添加机器名 (linux添加机器名)

在Linux系统中,使用机器名是非常重要的一件事情,在网络环境中可以通过机器名来识别不同的主机,也可以方便地进行文件共享和远程访问等操作。但是,一些Linux系统在安装时并没有为用户分配一个默认的机器名,造成一些不必要的困扰。因此,在使用Linux系统时,添加机器名是必须的一步。

本文将介绍,包括以下几个方面:

1. 查看当前机器名

2. 修改 /etc/hostname 文件

3. 更新 /etc/hosts 文件

4. 重启 Linux 系统

1. 查看当前机器名

我们需要确定当前系统正在使用的机器名,可以通过打开终端并使用以下命令来查看:

“`

hostnamectl

“`

该命令将显示当前正在使用的机器名。

2. 修改 /etc/hostname 文件

接下来,我们需要编辑 /etc/hostname 文件以添加新的机器名。该文件存储了系统当前正在使用的机器名,通过以下命令打开该文件进行编辑:

“`

sudo nano /etc/hostname

“`

在该文件中,可以找到当前正在使用的机器名,并用新的机器名替换它。替换后,保存并关闭文件。

3. 更新 /etc/hosts 文件

确保你在 /etc/hosts 文件中将旧的机器名都更新为新的机器名。打开该文件以进行编辑:

“`

sudo nano /etc/hosts

“`

在该文件中,可以找到一些与机器名相关的行。确保将这些行上的旧机器名都替换为新机器名,并且保存并关闭文件。

4. 重启 Linux 系统

要想新机器名生效,需要重新启动 Linux 系统。使用以下命令重启系统:

“`

sudo reboot

“`

重启后,你就可以看到新的机器名正在使用。

在Linux系统中,添加机器名是非常重要的一步,能够方便地进行文件共享和远程访问等操作。在本文中,我们介绍了如何在Linux中添加新的机器名。具体来说,包括查看当前机器名、修改 /etc/hostname 文件、更新 /etc/hosts 文件和重启系统等步骤。如果你正在使用Linux系统并需要添加新的机器名,可以根据上述步骤来进行操作。

相关问题拓展阅读:

虚拟机Linux上部署DB2pureScale过程

在Linux 操作系统 中,可在虚拟机上搭建DB2 pureScale,那么搭建的步骤是怎么样的呢?DB2 pureScale又有什么用呢?下面随我一起来了解下Linux系统如何在虚拟机上部署DB2 pureScale。

  在虚拟机Linux上部署DB2pureScale实践过程

、环境准备

  硬件环境:3 台 x86-64虚拟机,内存要求 1.5G 或以上(主要针对虚拟机,内存过低会造成数据库实例启动失败)

  操作系统:Suse Linux Enterprise Server 11.3

  DB2 版本:DB2 v10.5

  机器名:node01 node02 node03

  IP:192.168.18..168.18..168.18.203

  网关:192.168.18.2

  利用iscsi服务来做共享存储功能,其中node01 作为 iscsi 的 Server,node01、node02和 node03 作为 iscsi Client,这样三台虚拟机上都能看到相同的磁盘了(按照developer workers上的 文章 :非 InfiniBand 环境下搭建 DB2 pureScale,我用DB2 v10.5时启动实例失败,可能10.5做了限制,CF与member在同一台机器启动失败,帮多了一台虚拟机)。

、操作系统安装:

  Node01预留出一块分区,不进行格式化(文件类型为0x83 Linux)做为 pureScale 集群的 Sharing Disk 使用,Node02与Node03跟node01 其帆戚它 相同就可,

  安装必要的包:

  libstdc++(32 位和 64 位库)

  glibc(32 位和 64 位库)

  cpp

  差轿手gcc

  gcc-c++

  kernel-source

  binutils

  ksh-93u-0.8.1

  openssh

  ntp

  完成SUSE 11 SP3的安装。

  验证:检查/lib/modules/3.0.76-0.11-default/build/include/linux有无autoconf.h,如果没有autoconf.h,安装DB2时会报Compiling GPL :…….Failure错误。

  解决 方法 :cp –v /usr/src/linux-3.0.76-0.11-obj/x86_64/default/include/generated /lib/modules/3.0.76-0.11-default/build/include/linux

、添加用户和用户组

  三台机器全部执行如下命令(如果虚嫌不做特殊说明,以#表示root身份登录,以$表示db2inst1身份,以下相同)。

  #groupadd -g 1001 db2fadm1

  #groupadd -g 1002 db2iadm1

  #useradd -g db2fadm1 -um -d /home/db2fenc1 -p db2fenc1 db2fenc1

  #useradd -g db2iadm1 -um -d /home/db2inst1 -p db2inst1 db2inst1

  #mkdir /root/.ssh

  # su – db2inst1 -c “mkdir -p /home/db2inst1/.ssh”

、配置ssh 信任连接

  ssh信任通俗的说就是直接ssh不用输入密码

  在/etc/hosts添加另外两台机器的IP地址及机器名(确保3台机器名与ip地址全部出现在hosts文件中)

  例如我的机器hosts如下:

.0.0.1 localhost

.168.18.201 node01.site node01

.168.18.202 node02.site node02

.168.18.203 node03.site node03

  node01执行如下命令:

  #ssh-keygen -t rsa

  #cp -v /root/.ssh/id_rsa.pub /root/.ssh/id01

  #scp /root/.ssh/id01 node02:/root/.ssh

  #scp /root/.ssh/id01 node03:/root/.ssh

  #su – db2inst1

  $ssh-keygen -t rsa

  $cp -v /home/db2inst1/.ssh/id_rsa.pub /home/db2inst1/.ssh/id01

  $scp /home/db2inst1/.ssh/id01 node02:/home/db2inst1/.ssh

  $scp /home/db2inst1/.ssh/id01 node03:/home/db2inst1/.ssh

  node02执行如下命令:

  #ssh-keygen -t rsa

  #cp -v /root/.ssh/id_rsa.pub /root/.ssh/id02

  #scp /root/.ssh/id02 node01:/root/.ssh/

  #scp /root/.ssh/id02 node03:/root/.ssh/

  #su – db2inst1

  $ssh-keygen -t rsa

  $cp -v /home/db2inst1/.ssh/id_rsa.pub /home/db2inst1/.ssh/id02

  $scp /home/db2inst1/.ssh/id02 node01:/home/db2inst1/.ssh/

  $scp /home/db2inst1/.ssh/id02 node03:/home/db2inst1/.ssh/

  node03执行如下命令:

  #ssh-keygen -t rsa

  #cp -v /root/.ssh/id_rsa.pub /root/.ssh/id03

  #scp /root/.ssh/id03 node01:/root/.ssh

  #scp /root/.ssh/id03 node02:/root/.ssh

  #su – db2inst1

  $ssh-keygen -t rsa

  $cp -v /home/db2inst1/.ssh/id_rsa.pub /home/db2inst1/.ssh/id03

  $scp /home/db2inst1/.ssh/id03 node01:/home/db2inst1/.ssh/

  $scp /home/db2inst1/.ssh/id03 node02:/home/db2inst1/.ssh/

  分别在node01、node02、node03执行如下命令

  #cd /root/.ssh

  #cat id01 id02 id03 > authorized_keys

  #chmod 600 authorized_keys

  #su – db2inst1

  $cd /home/db2inst1/.ssh

  $ cat id01 id02 id03 > authorized_keys

  测试是否配置成功

台机器分别以root与db2inst1执行:

  #ssh node01 ls

  #ssh node02 ls

  #ssh node03 ls

  #su – db2inst1

  $ssh node01 ls

  $ssh node02 ls

  $ssh node03 ls

  确保不用输入密码,则配置成功。

、ISCSI 共享存储配置

  Iscsi server端配置(node01上执行):

  修改/etc/ietd.conf,添加如下内容:

  Target iqn..node01.site:scsidisk01

  Lun 0 Path=/dev/sda4,Type=fileio

  注意:我的未分区硬盘为/dev/sda4,你的可能不一样的@_@~~~~

  添加自启动

  #chkconfig -a iscsitarget

  检查是否成功

  #chkconfig -l iscsitarget

  结果:iscsitarget 0:off 1:off 2:off 3:on 4:off 5:on 6:off

  重启iscsitarget服务

  # /etc/init.d/iscsitarget restart

  iscsi client端配置(node01、node02、node03执行,):

  iscsitarget文件内容如下:

  #! /bin/sh

  ### BEGIN INIT INFO

  # Provides: iscsiclsetup

  #node02与node03上如果未装iscsitarget需将下下行的$iscsitarget

  # Required-Start: $network $syslog $iscsitarget $remote_fs artd

  # Required-Stop:

  # Default-Start: 3 5

  # Default-Stop:

  # Description: ISCSI client setup

  ### END INIT INFO

  case “$1” in start)

  iscsiadm –mode discoverydb –type sendtargets –portal 192.168.18.201 –discover

  iscsiadm –m node –targetname iqn..node01.site:scsidisk01 –portal 192.168.18.201:login

  ;;

  stop)

  iscsiadm -m node -T iqn..node01.site:scsidisk01 -p 192.168.18.201 –logout

  ;;

  restart) ## Stop the service and regardless of whether it was ## running or not, start it again.

  $0 stop

  $0 start

  ;;

  *)

  Esac

  保存后执行:#/etc/init.d/iscsiclient restart

  验证iscsiclient是否启动成功:

  #fdisk -l

  检查有无/dev/sdb出现

、配置Linux环境变量

  /etc/profie.local添加内容

  alias sl=’tail -f /var/log/messages’

  alias fc=’fcslogrpt /var/log/messages’

  export PATH=/root/bin:/usr/in/rsct/bin:/opt/ibm/db2/v10.5/bin:$PATH

  export PATH=/usr/lpp/mmfs/bin:$PATH

  export DB2USENONIB=TRUE

  export DB2_CFS_GPFS_NO_REFRESH_DATA=true

  然后执行# . /etc/profile.local,完成后你就可以安装purescale了,我猜测应该是设置了变量DB2USENONIB,使purescale不再要求你强制InfiniBand或万兆网卡,使我等穷人可以有机会玩这种高档、洋气、上档次的数据库。。。

、DB2 V10.5 的安装:

  node01:~/server_t # ./db2_install

  DBI1324W Support of the db2_install command is deprecated. For

  more information, see the DB2 Information Center.

  Default directory for installation of products – /opt/ibm/db2/V10.5

  ***********************************************************

  Install into default directory (/opt/ibm/db2/V10.5) ?

  yes

  Specify one of the following keywords to install DB2 products.

  SERVER

  CONSV

  EXP

  CLIENT

  RTCL

  Enter “help” to redisplay product names.

  Enter “quit” to exit.

  ***********************************************************

  server

  ***********************************************************

  Do you want to install the DB2 pureScale Feature?

  Yes

  曾经出现的错误:

  ERROR: An error occurred while compiling IBM General Parallel File System

  (GPFS) Portability Layer (GPL) on host “node01”. Return code “2”. GPL

  compilation log file location “/tmp/compileGPL.log.000”. The GPFS file system

  cannot be mounted properly until the GPL module is successfully compiled on

  this host. For details, see the specified GPL compilation log. After fixing

  the problems shown in the log file, re-run the DB2 installer. For information

  regarding the GPFS GPL module compile, see DB2 Information Center.

  Compiling GPL :…….Failure

  ERROR: A major error occurred while installing “DB2 Server Edition ” on this

  computer.

  解决方案:

  查看错误日志:compileGPL.log.000,为以下内容:

  cd /usr/lpp/mmfs/src/config; ./configure –genenvonly; if ; then /usr/bin/cpp -P def.mk.proto > ./def.mk; exit $? || exit 1; else exit $?; fi

  手工执行时会发现在./configure –genenvonly; 这一步报找不到

  /usr/bin/diff: /lib/modules/3.0.76-0.11-default/build/include/linux/autoconf.h: No such file or directory

  Kernel source tree does not have the correct autoconf.h file.

  See /usr/lpp/mmfs/src/README for further information

  手工拷呗一下autoconf.h文件即可

  #cp –v /usr/src/linux-3.0.76-0.11-obj/x86_64/default/include/generated/autoconf.h /lib/modules/3.0.76-0.11-default/build/include/linux/

  GPFS 文件系统配置与挂载

  方法1:使用db2cluster_prepare

  node01上执行:

  #/opt/ibm/db2/v10.5/instance/db2cluster_prepare -instance_shared_dev /dev/sdb

  DBI1446I The db2cluster_prepare command is running.

  DB2 installation is being initialized.

  Total number of tasks to be performed: 1

  Total estimated time for all tasks to be performed: 60 second(s)

  Task #1 start

  Description: Creating IBM General Parallel File System (GPFS) Cluster and Filesystem

  Estimated time 60 second(s)

  Task #1 end

  The execution completed successfully.

  For more information see the DB2 installation log at

  ”/tmp/db2cluster_prepare.log”.

  DBI1070I Program db2cluster_prepare completed successfully.

  此时df -l查看一下会发现多了一个挂载点

  node01:/opt/ibm/db2/V10.5/instance # df -l

  Filesystem 1K-blocks Used Available Use% Mounted on

  /dev/sda44% /

  udev8568 1% /dev

  tmpfs612 1% /dev/shm

  /dev/sda% /home

  /dev/db2fs% /db2sd_

  曾经出现报错:

  DBI20232E The DB2 installer detected that the variable record “GPFS_CLUSTER” is

  defined in the global registry. However, the GPFS cluster does not exist on

  host “node01”.

  Creating IBM General Parallel File System (GPFS) Cluster and Filesystem :…….Failure

  查看/tmp/ibm.db2.cluster.GuOypP发现有如下内容报错:

1-10.26.12.358494+480 I5385E400 LEVEL: Warning

  PID : 7469 TID :12 PROC : db2cluster

  INSTANCE: NODE : 000

  HOSTNAME: node01

  FUNCTION: DB2 UDB, oper system services, sqloMessage, probe:1

  MESSAGE : Cannot obtain registry variables

  DATA #1 : Hexdump, 4 bytes

x00007FFF: B400 0F87

  解决方案:由于此前我在此机器上试过N次db2cluster_prepare,包括V9.8、V10.1,V10.5安装,导致全局注册表变量没有删除干净,使用db2greg -dump

  V,GPFS_CLUSTER,NAME,db2cluster_.site,-,DB2_CREATED将其删除。

  #cp -v /var/db2/global.reg /var/db2/global.reg_

  #db2delgreg -delvarrec service= GPFS_CLUSTER

总结 :db2cluster_prepare这个命令失败时

  检查iscsi client是否准备好,fdisk -l查看一下是否有/dev/sdb

  全局注册表变量是否未删除干净 ,db2greg -dump查看

  检查一下是否tsa的domain存在,lsrpdomain,使用rmrpdomain将其删掉,如果其node为活动需先将其node停掉。具体参考tsa相关命令,

  检查一下gpfs cluster domain是否未清理干净,如果未清理干净,需要使用将fs、nsd、node清理掉,具体命令参考gpfs信息中心。

  方法2:手工挂载GPFS

  遇到过使用db2cluster_prepare时无法成功,手工安装(不确定是否遇到了 传说 中的bug)。

  创建cluster,不加-filesystem -disk选项:

  node01:

  #db2cluster -cfs -create -domain mydomain -host node01

  #db2cluster -cfs -add -host node02

  # db2cluster -cfs -add -host node03

  说明:上面如果不出故障当然可以加上-filesystem –disk参数,当然也可以用mmaddnode –N XXX来添加节点

  添加许可协议:

  提供两种方法

  #mmchlicense server –accept -N node01,node02,node03

  #/opt/ibm/db2/v10.5/bin/db2cluster -cfs -add -license

  创建nsd:任意node执行

  编写newNSD文件内容如下

  %nsd:

  device=/dev/sdb

  nsd=nsd1

  usage=dataAndMetadata

  #mmcrnsd -F /tmp/newNSD (-v no)

  如果报mmcrnsd: Disk device sdb refers to an existing NSD,而使用mmlsnsd 又查找不到相应的nsd,添加-v no可以跳过此验证。

  #mmlsnsd 查看创建的nsd名称,记下,在第3步时需要用到.

  创建Cluster File System并挂载

  启动所有node,任意node执行

  #mmstartup -a

  #mmgetstate -a

  确保所有node全部启动成功为active

  # mmcrfs -T /db2sd_db2sd_nsd1(此处的nsd1为第2步的nsd名称)

  #mmmount all -a

曾经出现的错误:mmstartup -a无响应

  ,查看日志/var/adm/ras/mmfs.log.previous

  Tue Apr 1 22:02:11 CST 2023: runmmfs starting

  Removing old /var/adm/ras/mmfs.log.* files:

  Unloading modules from /lib/modules/3.0.76-0.11-default/extra

  runmmfs: The /lib/modules/3.0.76-0.11-default/extra/mmfslinux.ko kernel extension does not exist.

  runmmfs: Unable to verify kernel/module configuration.

  Loading modules from /lib/modules/3.0.76-0.11-default/extra

  runmmfs: The /lib/modules/3.0.76-0.11-default/extra/mmfslinux.ko kernel extension does not exist.

  runmmfs: Unable to verify kernel/module configuration.

  Tue Apr 1 22:02:11 CST 2023 runmmfs: error in loading or unloading the mmfs kernel extension

  Tue Apr 1 22:02:11 CST 2023 runmmfs: stopping GPFS

  解决方案:重新编译一下gpfs的源码,因为手工卸载gpfs。

  /usr/lpp/mmfs/src/README有详细的编译方法:主要命令方法如下:

  #cd /usr/lpp/mmfs/src

  #make Autoconfig

  #make InstallImages

  make InstallImages会在/lib/modules/`uname -r`/extra目录生成3个文件,大功告成.

  创建实例

  创建实例前:

  node02#/opt/ibm/db2/V10.5/instance/db2icrt -cf node01 -cfnet node01

m node02 -mnet node02 -instance_shared_dir /db2sd_

tbdev 192.168.18.2 -u db2fenc1 db2inst1

tbdev 官方解释为:Specifies a shared device path for a device that will act as a tiebreaker in the DB2 pureScale environment to ensure that the integrity of the data is maintained. 通俗的讲就是在member出现故障时,判断哪个member可以恢复服务,穷丝们就用网关IP来代替了,只要能 ping 通即可判断为可用。

  此时执行:# db2instance -instance db2inst1 -list可以查看

  node01:/opt/ibm/db2/V10.5/instance # mmlscluster

  GPFS cluster information

  ========================

  GPFS cluster name: db2cluster_.site

  GPFS cluster id:235332

  GPFS UID domain: db2cluster_.site

  Remote shell command: /var/db2/db2ssh/db2locssh

  Remote file copy command: /var/db2/db2ssh/db2scp

  GPFS cluster configuration servers:

  Primary server: node01.site

  Secondary server: node02.site

  Node Daemon node name IP address Admin node name Designation

——

node01.site 192.168.18.201 node01.site quorum-manager

node02.site 192.168.18.202 node02.site quorum-manager

  曾经出现报错:

  错误1、报、,此类错误为创建tsa domain时的错误,原因在于虚拟机是拷贝的,不是重新安装的。

  解决方法:#/usr/in/rsct/install/bin/recfgct

  启动实例

  node01:$/home/db2inst1/sqllib/adm/db2start

  怎么样,报错了吧,应该是SQL1721N

  SQL1721N Starting the DB2 database manager failed because of a problem with a configuration file that is needed by RDMA.受打击吧。

  你装完了实例启动不了,没关系,这么高档的玩意怎么能让你这么快启动啊。

  你得设置两个注册表变量才能用普通网络.

  $db2set DB2_SD_SOCKETS_RESTRICTIONS=false

  $db2set DB2_CA_TRANSPORT_METHOD=SOCKETS

  使用如下命令可以查看CF与member的状态。

  #db2instance -instance db2inst1 -list

  node01:/home/db2inst1 # db2instance -instance db2inst1 -list

  ID TYPE STATE HOME_HOST CURRENT_HOST ALERT PARTITION_NUMBER LOGICAL_PORT NETNAME

MEMBER STARTED node02 node02 NO 0 0 node02

CF PRIMARY node01 node01 NO – 0 node01

  HOSTNAME STATE INSTANCE_STOPPED ALERT

  node01 ACTIVE NO NO

  node02 ACTIVE NO NO

  此时你可以使用lssam查看tsa的两个节点的状态。

  #lssam

  添加成员

  将node03添加为另一个member,如果实例没有启动会自动启动实例,所以预先将上一步的两台机器上的db2set执行完毕先。

  node01:

  #/opt/ibm/db2/v10.5/instance/db2iupdt -d -add -m node03 –mnet node03 db2inst1

  #su – db2inst1 -c “db2start member 1”

  开启你的purescale之旅

  #db2sampl

修改linux的网络配置方式有哪些?步骤?

图形界面就不说了 说下shell

—修改ip地址—

即时生效:

# ifconfig eth0 192.168.1.155 netmask 255.255.255.0

重启生效:

修改/etc/sysconfig/network-scripts/ifcfg-eth0

—修改default gateway—

即时生效:

# route add default gw 192.168.1.1

重启生效:

修改/etc/sysconfig/network-scripts/ifcfg-eth0

—修改dns—

修改/etc/基含resolv.conf

修改后即时生效,重启同样有效

—修改host name—

即时生效好锋旦:

# hostname test1

重启生效:

修改友扰/etc/sysconfig/network

在实际配置时,可以采用四种方法:

其一,基于控制面板法;

其二,基于X的linuxconf法;

三,基于Web浏览器的linuxconf法;

其四,手工使用命令法。

二、基于控制面板法

Linux的控制面板中的Network Configuration提供了易于掌握的集成化配置环境。首先检查在安装Red Hat Linux时是否安装了控制面板。

# rpm –ga grep control

如果安装了控制面板,则屏幕上显示:contrl –panel-3.7-7

如果未安装这个软件包,则键入如下命令:

# rpm –i /mnt/cdrom/Red Hat /rpms /usercfg-3.5-6.i386.rpm

单击控制面板窗口中的Network Configuration按钮,出现网络配置器窗口(如图1所示)。

1)Names标签

该标签提供了四个方面的信息:

(1) Hostname(主机名)

包括机器名和机器所在的完整域名。格式为:localhost.local domain,例如,

www.jbxue.com

,其中www为本地机主名字,jbxue.com为本机所在域名。

(2) Domain(域名)

机器所在的完整域名,即为主机名中的“。”后面部分。这里输入:linux.net

(3) Search for hostnames in additional domains(在其它域名中寻找主机名)

该项可不填。

(4) Nameservers(名字服务器)

即 DNS,这项列出了向网络提供域名服务的计算机名单,每行一个。若要提供名字服务器清单,则应给出ISP服务商提供的域名服务器的IP地址。例如:163.1.1.4、10.55.0.33 。

2) Hosts标签

该标签提供计算机的主机表,主机表放在/etc/host文件中。单击Hosts标签,并单击“Add”按钮,弹出对话框(图2)。

主机表文件包含机器名,IP地址及计算机替换名字。如果在小型网中,没有域名服务器,则主机表应包含所在网络中所有机器的名字和各自的IP地址。在连网的机器上缓槐至少有IP和name两项。对该表的操作包括增加(Add),编辑(edit),删除(remove)等操作。

首先编辑本地机项目,在IP栏输入163.1.5.125,Name栏输入

www.jbxue.com

,在nickname 栏中,可以

3)Interfaces标签

这是一个网络接口的配置标签。在缺省情况,该表中提供一个lo项目(本地回环设备),该项目不要删除,它是Linux网络工作时必需具备的一个项目,对应的IP地址为127.0.0.1。

如果用户现欲通过以太网卡接入Internet时,请选中表中eth0项目(注:之一个网卡设备名为 eth0, 第二个为eth1,依次类推)。单击“Remove”按钮,删除掉,然后单击“Add”按钮,弹出接口类型对话框(图3)。

请选中“Ethernet”单选项,单击“OK”按钮,出现edit Ethernet/Bus interface对话框。该对让猛话框包含以下内容:

(1) IP段 输入网卡物理地址,即本机IP地址。如163.1.5.125。

(2) Netmask字段 输入子网掩码,如255.255.0.0。

(3) Network字段 自动给出163.1.5.0。

(4) Broadcast字段 自动给出

(5) Activate interface at boot time单选项 在每次启动时,激活接口,以便使用网络,建议选择该项。

(6) Allow any user to (de)activate interface选项 允许任一用户激活或关闭网络接口。对于PPP之类的拨号接口中,每个用户都要建立网络连接,因此可以选择该项。对于以太网连接的用户,则不必选择该项。

(7) Interface configuration protocol选项 接口配置协议。指定服务器向工作站提供网络操作所需信息。可让本机在每次激活接口时从服务器取得配置。它有none,BOOT和DHCP三个选项。一般选择“none”。

4)Routing标签

该标签用于配置路由。告诉计算机如何把某些数据传到网络上的目标主机。如果网络使用缺省网关,则只要指出缺省网关IP地址以及本机网卡etho。

对以上四个标签操作完成后,单击网络配置器窗口中的“save”按钮,存盘退出。

三、基于X的linuxconf法

首先由root用户登录Linux系统,在Gnome环境中,单击脚印按钮,指向“system”,选择“control-panel”子项,以便启动控制面板,然后单击System Configuration图标。或者单击脚印按钮,指向“system”选项,选择linuxconf选项),出现linuxconf在xterm中的工作界面(见图4)。

⑴打开“Networking / Client tasks / Basic host Information”分支,选择Host name标签,输入主机名字;选择Adaptor 1标签,选中“enable”选项,表示能够使用之一个网卡;选择配置方式为Manual;然后分别填写:Primary name + domain(主机名。域名,如:lgx.linux.net)、IP address(主机的IP地址,如:163.1.5.125)、Net mask(子网掩码,如:255.255.0.0)、Net device(网络设备名eth0)、Kernel module(内核模块,如果是ne2023的网卡,那么应输入ne)、 I/O port(I/O端口地址,如0x300)、Irq>(中断号,如3)等选项。

⑵打开“Networking / Client tasks / Name Server Specification(DNS)”分支,弹出Resolve configuration对话框,选中“DNS is required for normal operation”;然后填写:Default domain (缺省域名)和Nameserver1(之一个DNS服务器的IP地址,如:163.1.1.4;在下一行,还可填写第二个DNS服务器的IP地址,如10.55.0.33)选项。

⑶打开“Config / Networking / Routing and gateways”选项,弹出的Defaults对话框,在Default gateway字段填写缺省的网关IP值,如:163.1.1.254,并选中“enable routing”选项。

⑷接受以上写入值,激活并退出。

注:在提示符“#”下,若执行linuxconf,则在xterm终端下配置方法与之相类似。

四、基于Web的Linuxconf法

在Red Hat Linux 6.0中,linuxconf也可工作在Web浏览器环境,操作方法是:

⑴在gnome-linuxconf对话框中,打开“Config / Networking / Misc / Linuxconf network access”分支。

⑵在对话框中输入任何允许使用Linuxconf的计算机的主机名,包括用户主机名字。

⑶选择“Accept”按钮,并按空格键,单击“Quit”按钮。

⑷启动Netscape浏览器,在URL栏键入:

其中,必选项hostname应换成用户计算机的主机名。

⑸选择浏览器页面底部的“Start”按钮,在弹出的口令验证框中,分别输入root和相应的口令,如果口令正确,

则进入如图5所示的Linuxconf工作环境。

⑹点击config框下的“Networking”选项,弹出Network Configurator页面,在其中的Client tasks框内,点击“Basic host information”、“Name server specification(DNS)”、“Routing and gateways”,分别输入主机信息、名字服务器及路由和网关等信息。

⑺操作完成后,存盘退出。

五、手工使用命令法

手工使用命令法是基于以太网卡已装入的情况下,编辑配置文件来配置网络的方法。具体步骤如下:

⑴ 编辑/etc/rc.d/rc.local文件

在该文件中加入类似下列各行:

#配置之一个以太网卡eth0的IP地址,子网掩码,UP起激活作用

/in/ifconfig,etho 163.1.5.125 netmask 255.255.0.0 UP

#配置并激活回环设备lo

/in/ifconfig lo 127.0.0.1 UP

/in/route add –host 127.0.0.1 lo

#让Linux将本地网的信息发送到eth0接口

/in/route add –net 163.1.5.125 netmask 255.255.0.0 eth0

#指定访问远程网络的缺省网关,假定缺省网关的IP地址为163.1.1.254

/in/route default gw 163.1.1.254 eth0

⑵ 编辑/etc/resdv.conf文件

该文件作用是设置名称服务器。可加入下列内容。

#指定本机域名为jbxue.com。

Domain jbxue. com

#域名称服务器(DNS),可以是本地网,也可以是远程网上的。按nameserver的顺序#逐一查找。若未找到,则Linux放弃寻找。

Nameserver 163.1.1.4

Nameserver 10.55.0.33

⑶ 编辑/etc/hosts.conf文件

设置主机文件表。可加入如下行:

order hosts,bind

multi on

163.1.5.125

www.jbxue.com

www

之一行表示:查找名称时,首先检查本地主机文件(hosts),然后按/etc/resolv.conf所指定的Nameservers顺序查找。

第三行列出主机IP地址、主机名和别名。

对/etc/rc.d/rc.local,/etc/hosts.conf,/etc/resolv.conf三个文件编辑后,必须重新启动机器。

五、结束语

综上所述,只要采用其中的任意一种方法,定义主机名字、主机表、网络接口设备及路由等参数,配置好Linux以太网,就能接入Internet,享受Internet提供的服务。

linux添加机器名的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于linux添加机器名,如何在Linux中添加机器名,虚拟机Linux上部署DB2pureScale过程,修改linux的网络配置方式有哪些?步骤?的信息别忘了在本站进行查找喔。


数据运维技术 » 如何在Linux中添加机器名 (linux添加机器名)