IP Address

Network Layers

OSI Model
7 Application Layer
6 Presentation Layer
5 Session Layer
4 Transport Layer
3 Network Layer
2 Data Link Layer (LLC sublayer, MAC sublayer)
1 Physical Layer

MAC Address

MAC address is a unique identifier assigned to network interfaces for communications on the physical network segment. Logically, MAC addresses are used in the Media Access Control protocol sub-layer of the OSI reference model. MAC addresses are most often assigned by the manufacturer of a network interface card (NIC) and are stored in its hardware, the card's read-only memory, or some other firmware mechanism.

IP v4

­To make it easier to remember, IP addresses are normally expressed in decimal format (124.665.234.123) but computers communicate in binary form: 11011000.00011011.00111101.10001001. ­­Each section is called an octet; each octet can hold 0-255 so this is a 32 bit address (8*4) and can have 2^32 IP addresses. The first octet is called Net section (least significant) and the last octet is Host or Node section (most significant). They are used to identify classes of IPs. the two middle octets are used by net and host sections when needed depending on the class.

Classes

There are five IP classes (A,B,C,D,E) plus certain special addresses:

  • Broadcast - Messages that are intended for all computers on a network are sent as broadcasts. These messages always use the IP address 255.255.255.255.
  • Class D - Used for multicast. Class D is slightly different from other classes. It has a first bit value of 1, second bit value of 1, third bit value of 1 and fourth bit value of 0. The other 28 bits are used to identify the group of computers the multicast message is intended for.
  • Loopback - The IP address 127.0.0.1 is used as the loopback address. This means that it is used by the host computer to send a message back to itself for troubleshooting and network testing.
  • Default Network - The IP address of 0.0.0.0 is used for the default network.

NAT

Network address translation is the process of modifying network address information in datagram (IP) packet headers while in transit across a traffic routing device for the purpose of remapping one IP address space into another. NAT is used in conjunction with network masquerading (or IP masquerading) which is a technique that hides an entire IP address space, usually consisting of private network IP addresses, behind a single IP address in another, often public address space. This mechanism is implemented in a routing device that uses stateful translation tables to map the "hidden" addresses into a single IP address and re-addresses the outgoing Internet Protocol (IP) packets on exit so that they appear to originate from the router.

Subnet

A subnetwork, or subnet, is a logically visible subdivision of an IP network.The practice of creating subnetworks is called subnetting.
All computers that belong to a subnet are addressed with a common, identical, most-significant bit-group in their IP address. This part of the address is known as the routing prefix or network number.
When subnetting and ip address of the form NetworkPrefix.HostNumber is divided into NetworkPrefix.SubnetNumber.HostNumber
The size of the routing prefix may be indicated using CIDR notation or through specification of a subnet mask.
A routing prefix may be expressed in CIDR notation. For example, 192.168.1.0/24 describes an IPv4 subnet starting at 192.168.1.0, having 24 bits allocated for the prefix, and the remainder, 8 bits, reserved for host addressing.
The routing prefix may also be described by a logical AND operation of a bit mask applied to an address within the network. In IPv4, the mask is called the subnet mask and is expressed in quad-dotted decimal representation (a.b.c.d). For example, 255.255.255.0 is the network mask for the 192.168.1.0/24 prefix. (?)
IPv6 uses a similar / (forward slash) notation to IPv4 CIDR (Classless Interdomain Routing) which describes the number of contiguous bits used in its netmask. Formally this way of writing an address is called an IP prefix but more commonly called the slash format: fe80::fcfd:4aff:fecf:f4ee/64

The prefix length for an IPv6 subnet will always be /64; This is not the case with ipv4.

IPv6

These IPs require eight 16-bit hexadecimal colon-delimited blocks: 2001:0db8:3c4d:0015:0000:0000:abcd:ef12 , 1080:0:0:0:0:34:0:417A , 1080::34:0:417A. So it will be a 128-bit address and we have a maximum of 2¹²⁸ addresses available.
Under IPv4 we have unicast, broadcast and multicast addresses. In IPv6 we have unicast, multicast and anycast. With IPv6 the broadcast addresses are not used anymore, they are replaced with multicast addressing.
1080::8:800:200C:417A = 1080:0:0:0:8:800:200C:417A

Unspecified address (:: corresponding to 0.0.0.0 in IPv4)

This is also called anylocal or wildcard address. If a socket is bound to an IPv6 anylocal address on a dual-stack machine, it can accept both IPv6 and IPv4 traffic; if it is bound to an IPv4 (IPv4-mapped) anylocal address, it can only accept IPv4 traffic. We always try to bind to IPv6 anylocal address on a dual-stack machine unless a related system property is set to use IPv4 Stack. Java by default would prefer IPv4 addresses over IPv6 addresses, when querying the name service (e.g., DNS service), we would return Ipv4 addresses ahead of IPv6 addresses.
The Unspecified Address also called anylocal or wildcard address must never be assigned to any node. It indicates the absence of an address. One example of its use is as the target of bind, which allows a server to accept a client connection on any interface, in case the server host has multiple interfaces.

Loopback address (::1 corresponding to 127.0.0.1 in IPv4)

Packets with the loopback address must never be sent on a link or forwarded by an IPv6 router. There are two separate loopback addresses for IPv4 and IPv6 and they are treated as such.
IPv4 and IPv6 addresses are separate address spaces except when it comes to "::".

Compatibility address ::w.x.y.z

This is used for hosts and routers to dynamically tunnel IPv6 packets over IPv4 routing infrastructure. It is meaningful for OS kernel and routers. IPv4-compatible IPv6 addresses are only used for devices that are actually IPv6-aware; the IPv4-compatible address is in addition to its conventional IPv6 address.

::129.144.52.38 is an IPv4-compatible IPv6 address.

IPv4-mapped address ::ffff:w.x.y.z

So in short, ipv4-mapped addresses are conventional IPv4 devices whose IPv4 address has been mapped into the IPv6 format and it is not an IPv6-capable device are used for devices that are only IPv4-capable.

These are used to represent an IPv4 address for hybrid dual stack systems. It allows the native program to use the same address data structure and also the same socket when communicating with both IPv4 and IPv6 nodes. Thus, on a dual-stack node with IPv4-mapped address support, an IPv6 application can talk to both IPv4 and IPv6 peer. The OS will do the underlying plumbing required to send or receive an IPv4 datagram and to hand it to an IPv6 destination socket, and it will synthesize an IPv4-mapped IPv6 address when needed.
For Java, it is used for internal representation; it has no functional role. Java will never return an IPv4-mapped address. It understands IPv4-mapped address syntax, both in byte array and text representation. However, it will be converted into an IPv4 address.
::FFFF:129.144.52.38 is the general form of an IPv4-mapped IPv6 address.

This address type has its first 80 bits set to zero and the next 16 set to one, while its last 32 bits are filled with the IPv4 address.

So, if an IPv4 device has the address 222.1.41.90, it would be represented as 0:0:0:0:0:FFFF:222.1.41.90, or ::FFFF:222.1.41.90.

6to4 address

(?)A special class of IPv6 addresses that have an embedded IPv4 in them. The embedded addresses are used to perform automatic IPv6-over-IPv4 tunneling.
http://en.wikipedia.org/wiki/6to4 (???)

Scopes

node-local

Node-local addresses are used to send packets to the same node. Loopback address and Node-local multicast address are link-local.

Link-local

Link-local addresses are used to communicate between hosts on the link. Link-local addresses are always configured automatically.
The following list shows the types of link-local addresses:

  • Unspecified address
  • Link-local Unicast address
  • Link-local Multicast address

Because all link-local addresses in a host have a common prefix, normal routing procedures cannot be used to choose the outgoing interface when sending packets to a link-local destination. A special identifier, known as a zone index is needed to provide the additional routing information; in the case of link-local addresses, zone indices correspond to interface identifiers.

When an address is written textually, the zone index is appended to the address, separated by a percent sign (%). The actual syntax of zone indices depends on the operating system:

  • the Microsoft Windows IPv6 stack uses numeric zone indexes, e.g., fe80::3%1. The index is determined by the interface number;
  • Unix-like systems use the interface name as a zone index: fe80::3%eth0.

Zone index notation % causes syntax conflicts when used in URIs!

Global

Addresses are unique across the internet.
The following list shows the types of global addresses:

  • Global Unicast address
  • Other scope Multicast address

IPv6 Ranges

Go with the CIDR format: http://efreedom.com/Question/1-774976/IPv6-Address-Ranges
To find out if an ipv4 is in range (ip_1, ip_2) you can convert them to long and check if ip will be in the range. For ipv6 convert to string representation of 128 bits and check with CIDR.

Addressing (Routing Schemes)

There are four forms of IP addressing, each with its own unique properties:

Unicast

The most common concept of an IP address is in unicast addressing, available in both IPv4 and IPv6. It normally refers to a single sender or a single receiver, and can be used for both sending and receiving. Usually, a unicast address is associated with a single device or host, but it is not a one-to-one correspondence. Some individual PCs have several distinct unicast addresses, each for its own distinct purpose. Sending the same data to multiple unicast addresses requires the sender to send all the data many times over, once for each recipient.

Broadcast

In IPv4 it is possible to send data to all possible destinations ("all-hosts broadcast"), which permits the sender to send the data only once, and all receivers receive a copy of it. In the IPv4 protocol, the address 255.255.255.255 is used for local broadcast. In addition, a directed (limited) broadcast can be made by combining the network prefix with a host suffix composed entirely of binary 1s. For example, the destination address used for a directed broadcast to devices on the 192.0.2.0/24 network is 192.0.2.255. IPv6 does not implement broadcast addressing and replaces it with multicast to the specially-defined all-nodes multicast address.
A broadcast address is an address that allows information to be sent to all machines on a given subnet, rather than a specific machine. Generally, the broadcast address is found by obtaining the bit complement of the subnet mask and performing a bitwise OR operation with the network identifier. In other words, the broadcast address is the last address in the range belonging to the subnet. In our example, the broadcast address would be 192.168.5.255, so to avoid confusion this address also cannot be assigned to a host. On a Class A, B, or C subnet, the broadcast address always ends in 255.

IPv6 does not implement traditional IP broadcast, i.e. the transmission of a packet to all hosts on the attached link using a special broadcast address, and therefore does not define broadcast addresses. In IPv6, the same result can be achieved by sending a packet to the link-local all nodes multicast group at address ff02::1, which is analogous to IPv4 multicast to address 224.0.0.1.

Multicast

A multicast address is associated with a group of interested receivers. In IPv4, addresses 224.0.0.0 through 239.255.255.255 (the former Class D addresses) are designated as multicast addresses. The sender sends a single datagram from its unicast address to the multicast group address and the intermediary routers take care of making copies and sending them to all receivers that have joined the corresponding multicast group. IPv6 uses the address block with the prefix ff00::/8 for multicast applications.
IP multicast is a technique for one-to-many communication over an IP infrastructure in a network. It scales to a larger receiver population by not requiring prior knowledge of who or how many receivers there are. Multicast uses network infrastructure efficiently by requiring the source to send a packet only once, even if it needs to be delivered to a large number of receivers. The nodes in the network take care of replicating the packet to reach multiple receivers only when necessary.

The most common transport layer protocol to use multicast addressing is User Datagram Protocol (UDP). By its nature, UDP is not reliable—messages may be lost or delivered out of order. Reliable multicast protocols such as Pragmatic General Multicast (PGM) have been developed to add loss detection and retransmission on top of IP multicast.

IP multicast is widely deployed in enterprises, commercial stock exchanges, and multimedia content delivery networks. A common enterprise use of IP multicast is for IPTV applications such as distance learning and televised company meetings.[citation needed]

An IP multicast group address is used by sources and the receivers to send and receive multicast messages. Sources use the group address as the IP destination address in their data packets. Receivers use this group address to inform the network that they are interested in receiving packets sent to that group. For example, if some content is associated with group 239.1.1.1, the source will send data packets destined to 239.1.1.1. Receivers for that content will inform the network that they are interested in receiving data packets sent to the group 239.1.1.1. The receiver joins 239.1.1.1. The protocol typically used by receivers to join a group is called the Internet Group Management Protocol (IGMP).

Anycast

Like broadcast and multicast, anycast is a one-to-many routing topology. However, the data stream is not transmitted to all receivers, just the one (only one) which the router decides is the "closest" in the network. Anycast is useful for global load balancing and is commonly used in DNS communications.

CIDR

Classless Inter-Domain Routing (reads as sider!) is a compact specification of an IP address and its associated routing prefix. It is written like ip_prefix/prefix_length where the prefix_length is the number of leading (starting - from left) 1 bits of the routing prefix as a decimal number (0-32)
10.10.1.32 = 00001010.00001010.00000001.001 00000
10.10.1.44 = 00001010.00001010.00000001.001 01100 matches 10.10.1.32/27.

See Subnet section in this page.

IPv6 in Java

  • The Java networking stack will first check whether IPv6 is supported on the underlying OS. If IPv6 is supported, it will try to use the IPv6 stack. More specifically, on dual-stack systems it will create an IPv6 socket. On separate-stack systems things are much more complicated. Java will create two sockets, one for IPv4 and one for IPv6 communication. For client-side TCP applications, once the socket is connected, the internet-protocol family type will be fixed, and the extra socket can be closed. For server-side TCP applications, since there is no way to tell from which IP family type the next client request will come, two sockets need to be maintained. For UDP applications, both sockets will be needed for the lifetime of the communication.
  • IPv6 stack is preferred by default, since on a dual-stack machine IPv6 socket can talk to both IPv4 and IPv6 peers. This setting can be changed through the java.net.preferIPv4Stack=<true|false> or java.net.preferIPv6Addresses=<true|false> system property.
  • An alternative form that is sometimes more convenient when dealing with a mixed environment of IPv4 and IPv6 nodes is x:x:x:x:x:x:d.d.d.d, where the 'x's are the hexadecimal values of the six high-order 16-bit pieces of the address, and the 'd's are the decimal values of the four low-order 8-bit pieces of the standard IPv4 representation address.
  • To use with port: https://[2001:db8:85a3:8d3:1319:8a2e:370:7348]:443/

Scenario 1

host2(client-dual)
host1(server- only v4)
If host2 wants to talk to host1, it will create a V6 socket. It then looks up the IP address for host1. Since host1 only has a v4 protocol stack, it will only have IPv4 records in the name lookup service. So host2 will try to reach host1 using an IPv4-mapped address. An IPv4 packet will be sent by host2, and host1 will think it is communicating with a v4 client

Scenario 2

host1(client-only v4)
host2(server-dual)
If host2 is the server, it will first create a v6-type socket (by default), then it will wait for connections. Since host1 supports v4 only, it creates a v4-type socket. They resolves the name for host2. It only gets v4 address for host2, since it doesn't understand IPv6 address. So it connects to host2 using v4 address. A v4 packet will be sent on the wire. On host2, the dual stack will convert the v4 packet into a v6 packet with a v4-mapped address in it and hand it over to the v6 socket. The server application will handle it as if it is a connection from a v6 node.

Calculator

Reference

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License