Linux automatically switches IP addresses using shell programming

Source: Internet
Author: User
Linux uses shell programming to automatically switch the IPUbuntu system. because the IP addresses used in commuting are different, it is very troublesome to manually modify each time. Www.2cto.com made a batch processing by referring to the network materials today. The full text is as follows :#! /Bin/bash # automatically switch to and from work network address # Work IP address, Mac, Gateway... linux uses shell programming to automatically switch to the IP address Ubuntu system. because the IP addresses used in commuting are different, it is very troublesome to manually modify each time. Www.2cto.com made a batch processing by referring to the network materials today. The full text is as follows :#! /Bin/bash # automatically switch to and from work network address # Work IP address, Mac, gateway IP [0] = 192.168.0.2MAC [0] = 00: 01: 02: 03: 04: 05GW [0] = 192.168.0.1 # Off-duty IP address, Mac, gateway IP address [1] = 192.168.1.3MAC [1] = 00: 02: 03: 04: 05: 06GW [1] = 192.168.1.1 # set off time www.2cto.com off = 1630now =$ (date + % H % M) let int = $ now-$ off # echo $ now-$ off = $ int # Here we may need to further set the let id = $ now/$ off # echo $ id ifconfig eth0 downifconfig eth0 hw ether "$ {MAC [$ id]}" ifconfig eth0 up # no network service on Ubuntu? # Service network stopifconfig eth0 "$ {IP [$ id]}" netmask route 255.255.0route add-net default gw "$ {GW [$ id]}" # service network start sleep 1 echo" network Connected. "copy and save as [ip. sh, run terminal to enter the save directory, and run 【. /ip. sh. Of course, you can also add it to the startup program so that it will be automatically modified every time it is started.

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.