Set the network for Linux virtual machines and implement host name ssh access

Source: Internet
Author: User
Tags domain name server nameserver ssh access

Set the network for Linux virtual machines and implement host name ssh access

To install a virtual machine, you must set the Internet access permission to use the host name for ssh remote access control.

1. Set the hostname in linux and access the linux virtual machine through the hostname. 1.1. Modify the hosts file
Vim/etc/hosts #/etc/hosts contains the following content: 127.0.0.1 localhost. localdomain localhost4 localhost4.localdomain4: 1 localhost. localdomain localhost6 localhost6.localdomain6192.168.136.128 oracle_master

Save and exit.

1.2. Modify the network

You can directly modify the configuration file/etc/sysconfig/network.
Here is a HOSTNAME = yourname
You can simply modify it.
NETWORKING = yes
HOSTNAME = oracle_master

1.3. manually set the hostname
hostname oracle_master

PS: if the above three steps have been completed, but the hostname has not changed, check the following files to see if it is the previous hostname value.

[root@oraclem1 ~]# vim /etc/sysconfig/network[root@oraclem1 ~]# find / -name hostname/proc/sys/kernel/hostname/bin/hostname/usr/lib64/gettext/hostname[root@oraclem1 ~]# vim /proc/sys/kernel/hostnameoraclem1

We can see that it is the old value. Here we cannot modify it because it is read-only, so the reboot server needs to take effect. After reboot, the hostname becomes a new oracle_master.

The original csdn blog publishing address: http://blog.csdn.net/mchdba/article/details/493#has not been approved by the original blogger mchdba (Huang Shan), declined to reprint

1.4. set ip address and hostname ing locally in linux
[root@oracle_master ~]# vim /etc/hosts127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 oracle_master::1 localhost localhost.localdomain localhost6 localhost6.localdomain6192.168.136.128 oracle_master192.168.136.129 oracle_standby

In this way, you can log on remotely through ssh hostname, as shown below:

[root@oracle_master ~]# ssh oracle_standbyLast login: Thu Oct 22 05:58:40 2015 from 192.168.136.128[root@oracle_standby ~]# 
1.5. Set the ing on the local windows Server

Add
192.168.136.128 oracle_master

You can ping the hostname directly, as shown below:
C: \ Users \ Administrator> ping oracle_master

Pinging oracle_master [192.168.136.128] with 32 bytes of data:
Reply from 192.168.136.128: byte = 32 time <1 ms TTL = 64
Reply from 192.168.136.128: byte = 32 time <1 ms TTL = 64
Reply from 192.168.136.128: byte = 32 time <1 ms TTL = 64
Reply from 192.168.136.128: byte = 32 time <1 ms TTL = 64

Ping statistics for 192.168.136.128:
Packet: Sent = 4, received = 4, lost = 0 (0% lost ),
Estimated round-trip time (in milliseconds ):
Minimum = 0 ms, maximum = 0 ms, average = 0 ms

C:\Users\Administrator>

2. Set the network address on linux 2.1 set an IP address in eth0
[root@oracle_master ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0BOOTPROTO=noneHWADDR=00:0C:29:0A:79:E6IPV6INIT=yesNM_CONTROLLED=yesONBOOT=yesIPADDR=192.168.136.128NETMASK=255.255.255.0TYPE=EthernetGATEWAY=192.168.136.2USERCTL=no

After configuration, restart

The gateway here is obtained from the following method. In the top bar of VMware Workstation, select "edit" and then select "Virtual Network Editor (N )", select "VMnet8" and then "NAT settings (S )...", There is a "gateway IP (G):" followed by the gateway value, as shown in:

C: \ Users \ Administrator \ Pictures \ 1022 \ 1.png

HWADDR is obtained from the following method. Right-click the selected "oracle_master" Vm, right-click it, select "Settings (S)", and then select "network adapter ", select "Advanced (V )...", You can see the MAC address (M ). As shown in:

C: \ Users \ Administrator \ Pictures \ 1022 \ 2.png

2.2 set the domain name resolution configuration file so that the Internet can be accessed through the domain

Nameserver can be used to set the IP address of the dns domain name server of the local pc or the gateway address of the virtual machine. Here the gateway address is set:

[root@oracle_standby ~]# vim /etc/resolv.conf# Generated by NetworkManagernameserver 192.168.136.2

Test Internet

[root@oracle_standby ~]# ping www.baidu.comPING www.a.shifen.com (115.239.210.27) 56(84) bytes of data.64 bytes from 115.239.210.27: icmp_seq=1 ttl=128 time=89.6 ms64 bytes from 115.239.210.27: icmp_seq=2 ttl=128 time=312 ms^C--- www.a.shifen.com ping statistics ---2 packets transmitted, 2 received, 0% packet loss, time 1462msrtt min/avg/max/mdev = 89.618/200.892/312.166/111.274 ms[root@oracle_standby ~]# 
4. Some basic DNS knowledge

/Etc/resolv. conf
File function: DNS Client configuration file, set the IP address and DNS domain name of the DNS server
Related Files:/etc/host. conf
File Format:
Domainname Domain Name
Search Domain Name
Nameserver Primary_DNS_Server_IP_address
Nameserver Second_DNS_Server_IP_address

This file is a configuration file used by the domain name Parser (resolver, a database that resolves IP addresses based on the host name), for example:
Search oracledg.com
Nameserver 192.168.136.1
Nameserver 192.168.136.2
"Search domainname.com" indicates that when a host name that does not include a full domain name is provided, the suffix of domainname.com is added after the host name; "nameserver" indicates that the host specified by this address is the Domain Name Server when the domain name is resolved. The Domain Name Server is queried according to the order in which the file appears.
Domainname and search can exist at the same time or only one. nameserver can specify multiple
Sample file content:
Search oracledg.com
Nameserver 192.168.136.3

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.