---
title: IPSG Configuration
slug: enterprise-v5p2/ipsg-configuration
createdAt: 2025-12-03T10:34:00.008Z
---

# <font color="#1d50a2">Introduction</font>

IP Source Guard (IPSG) is a defense mechanism against IP address spoofing attacks. It checks whether a user on a specific VLAN interface is a legitimate user based on the source IP address and source MAC address in the IP packet. IPSG prevents malicious hosts from forging the IP addresses of legitimate hosts, ensuring that unauthorized hosts cannot access or attack the network by specifying their own IP addresses.

# <font color="#1d50a2">Explanation of Principles</font>

The method for user legitimacy checks involves comparing the source IP address and source MAC address in the IP packet with the static binding entries, DHCP Snooping entries, and ND Snooping security entries on the device. If there is a match with any of these entries, the IP packet is considered legitimate and forwarded. Otherwise, the packet is considered illegitimate and discarded.

For IP trusted interfaces, user legitimacy checks are not performed. For non-trusted interfaces, user legitimacy checks are necessary to prevent spoofed user attacks.

# <font color="#1d50a2">IPSG Configuration</font>

| **Configure Tasks**           | **Instructions** |
| ----------------------------- | ---------------- |
| Enable IPSG                   | Required         |
| Configure IPSG trusted  ports | Optional         |

## <font color="#1d50a2">Enabling IPSG</font>

| **Operation**                        | **Command**                                                    | **Description** |
| ------------------------------------ | -------------------------------------------------------------- | --------------- |
| Enter the system  configuration view | **configure  terminal**                                        |                 |
| Enter the VLAN view                  | **vlan**  *ID*                                                 |                 |
| Enable IPSG function                 | **ipv4-source-check enable**<br />**ipv6-source-check enable** |                 |

## <font color="#1d50a2">Configuring IPSG Trusted Ports</font>

For interfaces configured as IP Source Guard (IPSG) trusted interfaces, if IPSG is enabled for a specific VLAN on that interface, then all IP packets received on that interface with the corresponding VLAN ID are allowed to pass through without any further inspection.

| **Operation**                        | **Command**                                                                                                          | **Description** |
| ------------------------------------ | -------------------------------------------------------------------------------------------------------------------- | --------------- |
| Enter the system  configuration view | **configure  terminal**                                                                                              |                 |
| Enter the interface view             | **interface ethernet** *interface-id*                                                                                |                 |
| Configure IPSG trusted  ports        | **ipv4-source-check  trusted-interface vlan** *vlan-id*<br />**ipv6-source-check  trusted-interface vlan** *vlan-id* |                 |

# <font color="#1d50a2">Configuration Example</font>

<font color="#1d50a2">**Network requirements**</font>

Users access the network through the switch, all users are known to be under the same VLAN100, and all users access the network with IPv4 and IPv6 dual stack, the administrator wants to enable the security function on the switch to prevent illegal users from accessing the network through private IP addresses, where:

PC 4 is a silent terminal and needs to access the network by manually configuring the IP address

PC 2 is an illegal user with a simulated private IP address

::Image[]{src="https://app.archbee.com/api/optimize/zl-MD6bX0o2Ab3p8w66u1/cS8dSs-NKakabpQ4rrXAZ-20251203-103533.png" size="70" width="768" height="228" position="center" showCaption="false"}

<font color="#1d50a2">**Procedure**</font>

1. Omit the creation of VLAN and VLANif interface configuration
2. Enable DHCP relay function

```text
sonic(config)# dhcp-relay test v4 
sonic(config-dhcp-relay-test__v4)# down_link interface vlan 100
sonic(config-dhcp-relay-test__v4)# up_link interface 49
sonic(config-dhcp-relay-test__v4)# server_ip 10.10.1.1
sonic(config-dhcp-relay-test__v4)# loopback_interface loopback 0
sonic(config-dhcp-relay-test__v4)# exit
sonic(config)# dhcp-relay test1 v6 
sonic(config-dhcp-relay-test__v6)# down_link interface vlan 100
sonic(config-dhcp-relay-test__v6)# up_link interface 49
sonic(config-dhcp-relay-test__v6)# server_ip 4005::1
sonic(config-dhcp-relay-test__v6)# loopback_interface loopback 0
sonic(config-dhcp-relay-test__v6)# exit
```

3. Enabling DHCP Snooping

```text
sonic(config)# dhcp snooping enable
sonic(config)# interface vlan 100
sonic(config-vlanif-100)# dhcp-snooping enable
```

4. Configure the interface connected to DHCP Server as a trusted port

```text
sonic(config)# interface ethernet 49
sonic(config-if-49)# dhcp-snooping enable
sonic(config-if-49)# dhcp-snooping trusted
```

5. Enable IPSG function and configure Ethernet4 port as a trusted port

```text
sonic(config)# vlan 100
sonic(config-vlan-100)# ipv4-source-check enable
sonic(config-vlan-100)# ipv6-source-check enable
sonic(config-vlan-100)# ipv4-source-check trusted-interface Ethernet4
sonic(config-vlan-100)# ipv6-source-check trusted-interface Ethernet4
```

<font color="#1d50a2">**Verify configuration**</font>

1. View device configuration
   \# View IPSG feature configuration

```text
sonic# ipv4-source-check config 
+--------------+--------------+----------------------+
| Interfaces   | Check mode   | Trusted interfaces   |
+==============+==============+======================+
| Vlan100      | true         | ['Ethernet1']        |
+--------------+--------------+----------------------+
```

:::Paragraph{indent="1"}
\# View IPSGv6 feature configuration
:::

```text
sonic# ipv6-source-check config 
+--------------+--------------+----------------------+
| Interfaces   | Check mode   | Trusted interfaces   |
+==============+==============+======================+
| Vlan100      | true         | ['Ethernet1']        |
+--------------+--------------+----------------------+
```

2. PC 1, PC 3, PC4 can access the network normally, PC 2 cannot access the network, and the packet loss statistics of the security function are counted.
