Linux static ip setting

  

IP configuration:

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

DEVICE=eth0

BOOTPROTO=static

HWADDR=00:26:18:0B:38:C0

ONBOOT=yes

IPADDR=192.168.0.20

NETMASK=255.255.255.0

GATEWAY=192.168.0.1

IP Effective:

/sbin/ifdown eth0

/sbin/ifup eth0

Notify the gateway to update information:

/etc/init.d/network restart

Configuring DNS:

vi /etc/resolv.conf

nameserver 202.96.134.133

Resolve restart to take effect:

chattr +i /etc/resolv.conf

Change to read-only

Modify ip address

Effective immediately:

# ifconfig eth0 192.168.0.20 netmask 255.255.255.0

Startup Effective:

Modify /etc/sysconfig/network-scripts/ifcfg-eth0

Modify default gateway

Instant Effective:

# route add default gw 192.168.0.254

Startup:

Modify /etc/sysconfig/network-scripts/ifcfg-eth0

Modify dns

Modify /etc/resolv.conf

Immediately after modification, the startup is also valid

Modify host name

Effective immediately:

# hostname fc2

Startup: Modify /etc/sysconfig/network

etc/sysconfig/network-scripts/ifcfg-ethN File

In RedHat The configuration file of the system network device is saved in the "/etc/sysconfig/network-scripts" directory, ifcfg-eth0 contains the configuration information of the first network card, and ifcfg-eth1 contains the configuration information of the second network card.

The following is an example of a "/etc/sysconfig/network-scripts/ifcfg-eth0" file:

DEVICE=eth0 DEVICE=name name indicates the name of the physical device

IPADDR=xxxx IPADDR=addr addr indicates the IP address assigned to the card

NETMASK=255.255.255.0 NETMASK=mask mask indicates network mask

NETWORK=xxxx NETWORK=addr addr indicates network Address

BROADCAST=xxxx BROADCAST=addr addr indicates broadcast address

ONBOOT=yes ONBOOT=yes/no Whether to activate the card at startup

BOOTPROTO=none none: no need to start Protocol bootp: use bootp protocol dhcp: use dhcp protocol

USERCTL=no USERCTL=yes/no Whether to allow non-root users to control the device

If you want to manually modify the network address or on the new interface Adding a new web interface can be done by modifying the corresponding file (ifcfg-ethN) or creating a new one.

The manual command method is based on how to edit the configuration file to configure the network when the Ethernet card is loaded. The specific steps are as follows:

(1) Edit the /etc/rc.d/rc.local file

Add the following lines to the file:

#Configure the first ether IP address of the NIC eth0, subnet mask, UP activation

/sbin/ifconfig, etho 163.1.5.125 netmask 255.255.0.0 UP

#Configure and activate the loopback devicelo

/sbin/ifconfig lo 127.0.0.1 UP

/sbin/route add –host 127.0.0.1 lo

#Let Linux send local network information to eth0 interface< Br>

/sbin/route add –net 163.1.5.125 netmask 255.255.0.0 eth0

#Specify the default gateway for accessing the remote network, assuming the IP address of the default gateway is 163.1.1.254

/sbin/route default gw 163.1.1.254 eth0

(2) Edit the /etc/resdv.conf file

This file is used to set the name server. The following can be added.

#Specify the local domain name as linux.net.

Domain linux.net

#domain name server (DNS), can be local network, or remote network of. Find them one by one in the order of nameserver. If not found, Linux gives up looking.

Nameserver 163.1.1.4

Nameserver 10.55.0.33

(3) Edit the /etc/hosts.conf file

Set the host file table. You can add the following line:

order hosts,bind

multi on

163.1.5.125 lgx.linux.net lgx

The first line means: find For the name, first check the local host files (hosts), and then look up in the order of Nameservers specified by /etc/resolv.conf.

The third line lists the host IP address, host name, and alias.

After editing the three files /etc/rc.d/rc.local, /etc/hosts.conf, /etc/resolv.conf, you must restart the machine.

V. Conclusion

In summary, as long as you use any of these methods, define the host name, host table, network interface device and routing parameters, configure Linux Ethernet, You can access the Internet and enjoy the services provided by the Internet.

Copyright © Windows knowledge All Rights Reserved