<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>linux bash network ifconfig ip &#8211; VeriTeknik</title>
	<atom:link href="https://www.veriteknik.net.tr/en/tag/linux-bash-network-ifconfig-ip/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.veriteknik.net.tr/en/</link>
	<description>VeriTeknik Bilişim &#124; VeriTeknik Bilişim</description>
	<lastBuildDate>Wed, 17 Apr 2019 16:59:18 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>Getting Network Information in Bash Scripts</title>
		<link>https://www.veriteknik.net.tr/en/getting-network-information-in-bash-scripts/</link>
					<comments>https://www.veriteknik.net.tr/en/getting-network-information-in-bash-scripts/#respond</comments>
		
		<dc:creator><![CDATA[Mustafa Emre Aydın]]></dc:creator>
		<pubDate>Mon, 26 Nov 2012 10:05:44 +0000</pubDate>
				<category><![CDATA[LINUX]]></category>
		<category><![CDATA[Network]]></category>
		<category><![CDATA[linux bash network ifconfig ip]]></category>
		<guid isPermaLink="false">http://www.plugged.in/?p=666</guid>

					<description><![CDATA[<p>Sometimes when writing your bash scripts, you may need some information about the network, such as the IP addresses, both IPv4 and IPv6, broadcast addresses, netmasks and such. There are two very basic ways of getting the necessary information in Linux systems, you should either choose the ip addr show method, and parse what&#8217;s coming [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://www.veriteknik.net.tr/en/getting-network-information-in-bash-scripts/">Getting Network Information in Bash Scripts</a> appeared first on <a rel="nofollow" href="https://www.veriteknik.net.tr/en/">VeriTeknik</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Sometimes when writing your bash scripts, you may need some information about the network, such as the IP addresses, both IPv4 and IPv6, broadcast addresses, netmasks and such. There are two very basic ways of getting the necessary information in Linux systems, you should either choose the <strong>ip addr show</strong> method, and parse what&#8217;s coming out of it, or parse the output of <strong>ifconfig</strong>. Let&#8217;s deal with them both.</p>
<p><strong>The &#8220;ip addr show&#8221; method</strong></p>
<p>We will parse this output:</p>
<pre class="brush: text; gutter: true; first-line: 1">eaydin@eaydin:~$ ip addr show
1: lo: &lt;LOOPBACK,UP,LOWER_UP&gt; mtu 16436 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: &lt;BROADCAST,MULTICAST,UP,LOWER_UP&gt; mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:22:15:f6:55:e6 brd ff:ff:ff:ff:ff:ff
    inet 192.168.16.30/24 brd 192.168.16.255 scope global eth0
    inet6 fe80::222:15ff:fef6:55e6/64 scope link 
       valid_lft forever preferred_lft forever</pre>
<p>IP ADDRESS :</p>
<pre class="brush: bash; gutter: true; first-line: 1">ip addr show |grep -w inet |grep -v 127.0.0.1|awk '{ print $2}'| cut -d "/" -f 1</pre>
<pre class="brush: text; gutter: true; first-line: 1">Output : 192.168.16.30</pre>
<p>PREFIX (Netmask in CIDR Notation) :</p>
<pre class="brush: bash; gutter: true; first-line: 1">ip addr show |grep -w inet |grep -v 127.0.0.1|awk '{ print $2}'| cut -d "/" -f 2</pre>
<pre class="brush: text; gutter: true; first-line: 1">Output : 24</pre>
<p>Broadcast IP :</p>
<pre class="brush: bash; gutter: true; first-line: 1">ip addr show |grep -w inet |grep -v 127.0.0.1|awk '{ print $4}'</pre>
<pre class="brush: text; gutter: true; first-line: 1">Output : 192.168.16.255</pre>
<p>Device name :</p>
<pre class="brush: bash; gutter: true; first-line: 1">ip addr show | awk 'FNR==7 {print $2}' | tr -d :</pre>
<pre class="brush: text; gutter: true; first-line: 1">Output : eth0</pre>
<p>IPv6 ADDRESS :</p>
<pre class="brush: bash; gutter: true; first-line: 1">ip addr show |grep -w inet6 |grep -v ::1|awk '{ print $2}'| cut -d "/" -f 1</pre>
<pre class="brush: text; gutter: true; first-line: 1">Output : fe80::222:15ff:fef6:55e6</pre>
<p>IPv6 PREFIX (Netmask in CIDR Notation) :</p>
<pre class="brush: bash; gutter: true; first-line: 1">ip addr show |grep -w inet6 |grep -v ::1|awk 'FNR==1 { print $2}'| cut -d "/" -f 2</pre>
<pre class="brush: text; gutter: true; first-line: 1">Output : 64</pre>
<p>Ethernet Card MAC Address :</p>
<pre class="brush: bash; gutter: true; first-line: 1">ip addr show | grep -w ether | awk '{ print $2 }'</pre>
<pre class="brush: text; gutter: true; first-line: 1">Output : 00:22:15:f6:55:e6</pre>
<p><strong>The &#8220;ifconfig&#8221; method</strong></p>
<p>This time we&#8217;ll parse this output:</p>
<pre class="brush: text; gutter: true; first-line: 1">eaydin@eaydin:~$ ifconfig
eth0      Link encap:Ethernet  HWaddr 00:22:15:f6:55:e6  
          inet addr:192.168.16.30  Bcast:192.168.16.255  Mask:255.255.255.0
          inet6 addr: fe80::222:15ff:fef6:55e6/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:626934 errors:0 dropped:0 overruns:0 frame:0
          TX packets:363506 errors:0 dropped:0 overruns:0 carrier:2
          collisions:0 txqueuelen:1000 
          RX bytes:284072710 (284.0 MB)  TX bytes:56413838 (56.4 MB)
          Interrupt:45 

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:43339 errors:0 dropped:0 overruns:0 frame:0
          TX packets:43339 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:4834972 (4.8 MB)  TX bytes:4834972 (4.8 MB)</pre>
<p>IP ADDRESS :</p>
<pre class="brush: bash; gutter: true; first-line: 1">ifconfig | grep -w inet |grep -v 127.0.0.1| awk '{print $2}' | cut -d ":" -f 2</pre>
<pre class="brush: text; gutter: true; first-line: 1">Output : 192.168.16.30</pre>
<p>Broadcast IP :</p>
<pre class="brush: bash; gutter: true; first-line: 1">ifconfig | grep -w inet |grep -v 127.0.0.1| awk '{print $6}' | cut -d ":" -f 2

Output : 192.168.16.255</pre>
<p>Netmask :</p>
<pre class="brush: bash; gutter: true; first-line: 1">ifconfig | grep -w inet |grep -v 127.0.0.1| awk '{print $4}' | cut -d ":" -f 2</pre>
<pre class="brush: text; gutter: true; first-line: 1">Output : 255.255.255.0</pre>
<p>Device name :</p>
<pre class="brush: bash; gutter: true; first-line: 1">ifconfig | awk 'FNR==1 { print $1 }' | tr --d :</pre>
<pre class="brush: text; gutter: true; first-line: 1">Output : eth0</pre>
<p>IPv6 ADDRESS :</p>
<pre class="brush: bash; gutter: true; first-line: 1">ifconfig | grep -w inet6 | grep -v ::1| awk '{ print $2 }'

Output : fe80::222:15ff:fef6:55e6</pre>
<p>IPv6 PREFIX (Netmask in CIDR Notation) :</p>
<pre class="brush: bash; gutter: true; first-line: 1">ifconfig | grep -w inet6 | awk 'FNR == 2 { print $4 }'</pre>
<pre class="brush: text; gutter: true; first-line: 1">Output : 64</pre>
<p>Ethernet Card MAC Address :</p>
<pre class="brush: bash; gutter: true; first-line: 1">ifconfig | grep -w ether | awk '{ print $2 }'</pre>
<pre class="brush: text; gutter: true; first-line: 1">Output : 00:22:15:f6:55:e6</pre>
<p>The post <a rel="nofollow" href="https://www.veriteknik.net.tr/en/getting-network-information-in-bash-scripts/">Getting Network Information in Bash Scripts</a> appeared first on <a rel="nofollow" href="https://www.veriteknik.net.tr/en/">VeriTeknik</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.veriteknik.net.tr/en/getting-network-information-in-bash-scripts/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">666</post-id>	</item>
	</channel>
</rss>
