<p>In a shellscript, I'd like to set the IP of my box, run a command, then move to the next IP. The IPs are an entire C block.</p>

<p>The question is how do I set the IP of the box without editing a file? What command sets the IP on Slackware?</p>

<p>Thanks</p>

[{'answer_id': 74039, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': "<p>It should be something like: <code>ifconfig eth0 192.168.0.42 up</code></p>\n\n<p>Replace eth0 by the network interface of your network card, obviously adapt the ip address to your needs and the up is only necessary once, but doesn't hurt if you run it each time. </p>\n"}, {'answer_id': 74058, 'author': 'tialaramex', 'author_id': 9654, 'author_profile': 'https://Stackoverflow.com/users/9654', 'pm_score': 0, 'selected': False, 'text': "<p>I don't know Slackware very well, I last used it over ten years ago. However, any mainstream Linux distribution should have either the 'ifconfig' program, or the 'ip' program or both. You will need to have root privilges, so either become root (e.g with su) or use the 'sudo' program if you know how. Let's do it with 'ip' first.</p>\n\n<pre><code>ip addr add 10.1.2.3 dev eth0\n</code></pre>\n\n<p>sets the device eth0 (usually the primary wired network adaptor) to have IP address 10.1.2.3. You can remove the address from this adaptor again when you're done with it...</p>\n\n<pre><code>ip addr del 10.1.2.3 dev eth0\n</code></pre>\n\n<p>ifconfig works a bit differently,</p>\n\n<pre><code>ifconfig eth0 10.1.2.3 netmask 255.255.255.0\n</code></pre>\n\n<p>again sets up device eth0, with IP address 10.1.2.3</p>\n\n<p>Depending on what you want these addresses for, you may also need to know how to set up a manual route, so that your IP packets actually get delivered wherever they're going.</p>\n"}, {'answer_id': 75221, 'author': 'Thomee', 'author_id': 12825, 'author_profile': 'https://Stackoverflow.com/users/12825', 'pm_score': 2, 'selected': False, 'text': "<p>As mentioned in other answers, you can use either the ifconfig command or the ip command.  ip is a much more robust command, and I prefer to use it.  A full script which loops through a full class C subnet adding the IP, doing stuff, then removing it follows.  Note that it doesn't use .0 or .255, which are the network and broadcast addresses of the subnet.  Also, when using the ip command to add or remove an address, it's good to include the mask width, as well (the /24 at the end of the address).</p>\n\n<pre><code>#!/bin/bash\nSUBNET=192.168.135.\nETH=eth0\n\nfor i in {1..254}\ndo\n  ip addr add ${SUBNET}${i}/24 dev ${ETH}\n\n  # do whatever you want here\n\n  ip addr del ${SUBNET}${i}/24 dev ${ETH}\ndone</code></pre>\n"}, {'answer_id': 220745, 'author': 'Eduardo', 'author_id': 9823, 'author_profile': 'https://Stackoverflow.com/users/9823', 'pm_score': 0, 'selected': False, 'text': '<p>In one line, e.g.: ifconfig eth0 192.168.10.12 netmask 255.255.255.0</p>\n'}]
['https://Stackoverflow.com/questions/73958', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/']