SuSE Linux: Fast IP address Switching

Source: Internet
Author: User

YaST management in the SuSE graphic interface is very friendly and can easily and intuitively change the IP address of the NIC, but it is too slow. For network administrators who need to change IP addresses frequently like me, this is really a nightmare, so the graphical method is absolutely inefficient and must use commands.

In Linux, the system management operations on the graphic interface are actually encapsulation of commands. The interface friendliness and speed are in conflict. The operations are simple and the speed is slow, so Linux old bird generally do not need graphical interface to modify the configuration, Suse network configuration file stored in:/etc/sysconfig/network directory, which is similar to the ifcfg-eth-id-00: 40: CA: C7: 04: fc such a file is the configuration file of the Ethernet Card, the file name of 00: 40: CA: C7: 04: Fc for the MAC address of the network card, similar to ifcfg-wlan-id-00: 0C: F1: 1D: A5: 6d is the configuration file of the wireless network card. In the same file name, 00: 0C: F1: 1D: A5: 6d is the MAC address of the wireless network card, ifcfg-Lo is the configuration file for local loopback. The general configuration format of the ifcfg file is as follows:

 

BOOTPROTO='static'BROADCAST=''IPADDR='218.65.19.24'MTU=''NAME='FIRST INTERNATIONAL RTL-8139/8139C/8139C+'NETMASK='255.255.255.224'NETWORK=''REMOTE_IPADDR=''STARTMODE='auto'UNIQUE='JNkJ._Kgt7k3ca97'USERCONTROL='no'_nm_name='bus-pci-0000:02:05.0'

 

Ipaddr sets the IP address and netmask sets the subnet mask.

The routes file is the configuration file of the gateway and route table. Its format is generally as follows:

 

0.0.0.0 192.168.1.254 0.0.0.0 wlan-id-00:0c:f1:1d:a5:6ddefault 218.65.19.17 - -

 

Row 1st is a static route in the format of the Mac ID of the target subnet gateway mask Nic. I have such a routes route to facilitate manual addition, generally, there is no such routes. 2nd act as the default route, that is, the gateway settings. The IP address is the IP address of the gateway.

Since these files are available, you only need to modify the corresponding configuration file (ifcfg and routes). For convenience, you can save the configuration files that require frequent IP changes.(Do not save it in the network directory. If it is saved in this directory, the system will search for the Mac NIC with the ifcfg-eth-ID-followed character at startup, as a result, the system startup slows down, and the access speed to the xwindows system (such as ked and gnome) slows down)When you need to switch the IP address, copy the file to overwrite the configuration, and then restart the network using/etc/init. d/network restart.

For example, I need to switch between the two networks frequently. One IP address is 155.176.160.189/24 and the gateway is 155.176.160.254. The other IP address is 218.65.19.24/27 and the gateway is 218.65.19.17: for surfing the Internet, there is also a wireless network in the house, because you do not need to modify the IP address, but only modify the gateway. For convenience, I made two configuration files for the two networks, ifcfg-eth-id-00: 40: CA: C7: 04: fc, respectively. abis/routes. abis, ifcfg-eth-id-00: 40: CA: C7: 04: FC. internet/routes. internet, the wireless gateway is: route. home also creates a shell file chg_nets in the sbin directory to facilitate IP switching:

 

! /bin/shconfig_path=/etc/sysconfig/networkconfig_path=/etc/sysconfig/network/customcase "$1" in       home)                rm $config_path/ifcfg-eth-id-00:40:ca:c7:04:fc                cp $custom_path/routes.home $config_path/routes                cp $custom_path/ifcfg-wlan-id-00:0c:f1:1d:a5:6d.home $config_path/ifcfg-wlan-id-00:0c:f1:1d:a5:6d                /etc/init.d/network restart               ;;       internet)               cp $custom_path/routes.internet $config_path/routes               cp $custom_path/ifcfg-eth-id-00:40:ca:c7:04:fc.internet $config_path/ifcfg-eth-id-00:40:ca:c7:04:fc               /etc/init.d/network restart               ;;       abis)               cp $custom_path/routes.abis $config_path/routes               cp $custom_path/ifcfg-eth-id-00:40:ca:c7:04:fc.abis $config_path/ifcfg-eth-id-00:40:ca:c7:04:fc               /etc/init.d/network restart               ;;       *)               echo 'usage: chg_nets '               ;;esac

 

In this way, you only need to run the: chg_nets command in privileged user mode each time you need to switch the IP address. For example, you can switch to the Internet address chg_nets Internet.

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.